I am using the latest version of C++ and I am trying to run the following code. However, its keeps telling me that stoi is "not declared in this scope". I am new to C++ so please share if you have any ideas.
#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;
}