my question is pretty simple but I can't seem to find it out.I want to know what libary to include when using stoi. I was using atoi and it works fine with

#include <iostream>#include <string>#include <stdlib.h>using namespace std;

but I get "stoi not declared" when I run with stoi. Thanks

1

Best Answer


You need to #include <string> and use a compiler that understands C++11. Minimal example:

#include <string>#include <cassert>int main(){std::string example = "1234";int i = std::stoi(example);assert(i == 1234);return 0;}

Compile, for example, with g++ -std=c++11.