0

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;
}
OneMoreQuestion
  • 1,544
  • 2
  • 19
  • 43

1 Answers1

2

std::stoi is C++11 and above feature, Hence enable C++11 on your compilation.

In gcc or clang, the flag is -std=c++11

CXX -std=c++11 cc.cc

where CXX will be either g++ or clang++.

Please make this change also, in header inclusion part

#include <iostream>
#include <string>
using namespace std;
dlmeetei
  • 7,297
  • 3
  • 25
  • 34