User forums > General (but related to Code::Blocks)
Error stoi is not a member of std
(1/1)
lesterclayton:
According to http://en.cppreference.com/w/cpp/string/basic_string/stol, std::stoi is part of <string>, but when I try to compile the following code:
--- Code: ---#include <iostream>
#include <string>
int main()
{
std::string str1 = "45";
std::string str2 = "3.14159";
std::string str3 = "31337 with words";
std::string str4 = "words and 2";
//The error occurs on the next line
int myint1 = std::stoi(str1);
int myint2 = std::stoi(str2);
int myint3 = std::stoi(str3);
std::cout << "std::stoi(\"" << str1 << "\") is " << myint1 << '\n';
std::cout << "std::stoi(\"" << str2 << "\") is " << myint2 << '\n';
std::cout << "std::stoi(\"" << str3 << "\") is " << myint3 << '\n';
}
--- End code ---
I get the error "error: 'stoi' is not a member of 'std'"
I did some Googling and found that I apparently need the -std=c++11 flag to enable this feature, but I have this checkbox checked in my GNU GCC Compiler page, as follows:
Can anybody shed some more light on this issue for me please?
Using Code::Blocks 12.11 with mingw32-gcc (tdm-1) 4.7.1
stahta01:
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F
Edit1: Post the full "Build Log" or it is NOT possible to help you.
Edit2: Posting the exact error message is normally helpful, also.
Edit3: Looking like a Compiler Problem.
Tim S.
lesterclayton:
Thanks for the reply.
Here is the Debugged Build Log
--- Quote ----------------- Build: Debug in Stoi Example (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -Wall -fexceptions -g -std=c++11 -c "Z:\stuff\C++ Projects\Lesson 10\Stoi Example\main.cpp" -o obj\Debug\main.o
Z:\stuff\C++ Projects\Lesson 10\Stoi Example\main.cpp: In function 'int main()':
Z:\stuff\C++ Projects\Lesson 10\Stoi Example\main.cpp:12:18: error: 'stoi' is not a member of 'std'
Z:\stuff\C++ Projects\Lesson 10\Stoi Example\main.cpp:13:18: error: 'stoi' is not a member of 'std'
Z:\stuff\C++ Projects\Lesson 10\Stoi Example\main.cpp:14:18: error: 'stoi' is not a member of 'std'
Process terminated with status 1 (0 minutes, 0 seconds)
3 errors, 0 warnings (0 minutes, 0 seconds)
--- End quote ---
I was under the impression that I had posted the exact error message, which is "error: 'stoi' is not a member of 'std'", but thanks for the tip.
stahta01:
Looks like a Compiler problem to me; I suggest looking in the TDM thread or website for known issues.
Edit: Known issue in MinGW GCC 4.6 according to this thread http://stackoverflow.com/questions/8542221/stdstoi-doesnt-exist-in-g-4-6-1-on-mingw
Edit2: http://stackoverflow.com/questions/20145488/cygwin-g-stdstoi-error-stoi-is-not-a-member-of-std
Tim S.
lesterclayton:
Thank you :)
Navigation
[0] Message Index
Go to full version