C++ stoi 超出范围问题

C++ stoi out of scope issue

我正在使用最新版本的 C++,我正在尝试 运行 以下代码。但是,它一直告诉我 stoi 是 "not declared in this scope"。我是 C++ 的新手,所以如果您有任何想法,请分享。

#include <iostream>
using namespace std;

#include <iostream>
using namespace std;
#include <string>



int main(int argc, char *argv[])
{

int a;
for (int i=0; i<argc; i++)
{
    string str(argv[1]);

    a=stoi(str);


   if (a<1) {
       cout<< "the sequence length must be greater than 1"<<endl;
   } else {
       cout <<"consecutive "<< a<<endl; // prints the input number of required consecutive
   }
}

int num[1000000];
int n, j;
n=1;

for (int x=1;!cin.eof() ; ++x)
{
    cin>>num[x];

    if (cin.fail())
    {
        cout<< "error, only integers allowed"<<endl;
    break;
    }


    else if (x>=a)

    {
        while ( num[x-n+1] - num[x-n] == 1)

        { ++n;

        if (n == a)
        { cout<< "sequence found: " ;

        for (j=a-1; j >=0; --j)

            cout<< num[x-j]<<" ";
        break;
        }
        }
    }
}

cout<<endl;
return 0;
}

std::stoiC++11 及以上的特性,因此在编译时启用 C++11。

在gcc或clang中,标志是-std=c++11

CXX -std=c++11 cc.cc

其中 CXX 将是 g++clang++

请在 header 包含部分

中也进行此更改
#include <iostream>
#include <string>
using namespace std;