Reputation: 2581
Most probably this is weird, but when I got this error that stoi wasn't declared in this scope, I smiled because I am familiar with this error and it's solution.
I checked this option have g++ follow the c++11 ISO c++ language standard [-std=c++11] in compiler settings of Code Blocks (16.01, with MinGW) and tried recompiling it, but surprisingly it didn't work and the same error persisted. I tried re-installing CodeBlocks but that didn't work.
Also, I tried with windows power shell and command prompt with g++ math_handler.cpp -std=c++11
but got the same error.
What am I doing wrong?
the code is here:
#include<string>
using namespace std;
int main()
{
string body="456";
int i=stoi(body);
}
Note:
-std=c++0x
and g++ too.to_string()
function.Upvotes: 2
Views: 6577
Reputation: 2581
Okay, I found that it is a known bug in MinGW bundled with CodeBlocks. I found the solution here.
Download mingw-to-string-gcc47.zip which contains three patched header files. (Original patches: wchar.h, stdio.h, os_defines.h)
Copy wchar.h and stdio.h from the include directory in the zip file to the following directory (overwrite): C:\mingw\include (replace C:\mingw\ with the appropriate directory)
Copy os_defines.h to the following directory (overwrite): C:\mingw\lib\gcc\mingw32\4.7.0\include\c++\mingw32\bits (replace C:\mingw\ with the appropriate directory) (replace 4.7.0 with the correct version number)
Upvotes: 2
Reputation: 386
Did you include the required header file?
#include <string>
stoi is also in the std namespace so:
std::stoi()
or:
using namespace std;
Upvotes: 0