I've been trying to use the stoi (String to Integer) command, which is part of C++11, but I can't seem to get it to work. I've tried to compile in Dev-C++, Code::Blocks with C++11 on, and with the MinGW GCC/G++ (Version 4.8.1) with and without the -std=c++11/-std=c++0x lines, but every attempt has met with the compiler saying that 'stoi' has not been declared. Anyone know how to fix this or get it working?
In function 'int main()':
'stoi' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
[Build Error] [main.o] Error 1
Code::Blocks Result:
In function 'int main()':
'stoi' was not declared in this scope
'system' was not declared in this scope
Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s))
MinGW GCC/G++ Result:
main.cpp: In function 'int main()';
main.cpp:11:31: error: 'stoi' was not declared in this scope
int myInt = stoi (myString);
main.cpp:15:20: error: 'system' was not declared in this scope
system ("pause");
Note: The whole system pause bit is just a Dev-C++ thing for pausing the program, so the fact that it throws up an error in Code::Blocks and MinGW isn't actually an issue
well, can you show us stoi? Also, please always use code tags, its under the format section and looks like this <>. Mark all of your code and click it.
MingW 4.8.1's stdlib does have std::stoi. It's no bug.
"system" is inside stdlib.h.
Make sure you have -std=c++11 in your compiler's command line. That can be the only issue (unless you been toying with it too much).
MingW 4.8.1's stdlib does have std::stoi. It's no bug.
in compiler terms, not supporting a standard feature is considered a bug. for example, when gcc 4.8 didnt support <regex> it was labeled a bug. (that might not be the correct version/header, but i think you get the jist)
I've indirectly fixed the problem. Instead of trying to use C++11's stoi function, I've just changed the string to a char array and used the standard atoi function instead, which seems to be working fine.