c++ – Function stoi not declared

c++ – Function stoi not declared

std::stoi was introduced in C++11. Make sure your compiler settings are correct and/or your compiler supports C++11.

The answers above are correct, but not well explained.

g++ -std=c++11 my_cpp_code.cpp

Add -std=c++11 to your compiler options since you are most likely using an older version of debian or ubuntu which is not using by default the new c++11 standard of g++/gcc. I had the same problem on Debian Wheezy.


shows in really small writing to the right in green that c++11 is required.

c++ – Function stoi not declared

stoi is a C++11 function. If you arent using a compiler that understands C++11, this simply wont compile.

You can use a stringstream instead to read the input:

stringstream ss(hours0);
ss >> hours;

Leave a Reply

Your email address will not be published. Required fields are marked *