Hi.
I would like to use the function stoi, so I could convert a string to an int more easily. The problem is that everytime I try to use it, I get an error message saying: "'stoi' is not a member of 'std'".
I use Codeblocks and GNU gcc Compiler. I've always programmed in c++ instead of c++11 until now. I saw on the internet that to switch for c++11 in codeblocks, one just has to go to Project->Build Options->Compiler Flags and then enable:
-Have g++ follow the coming c++Ox ISO C++ language standard[-std=c++Ox];
-Have g++ follw the c++11 ISO C++ language standard[-std=c++11]
Have I done something wrong?
I really need help.
Thanks in advance
Also, one example of the codes that I write and then get a mistake is the following:
You only need to install 4.8.1 but then you need to tell Code::Blocks where the files are.In settings/compiler/Toolchain executables.
If I change only Compiler's instalation directory CodeBlocks tells me the following:
"The compiler's setup (GNU GCC Compiler) is invalid, so Code::Blocks cannot find/run the compiler.
Probably the toolchain path within the compiler options is not setup correctly?!
Goto "Settings->Compiler and debugger...->Global compiler settings->GNU GCC Compiler->Toolchain executables" and fix the compiler's setup.
Skipping..."
and I don't even get error messages(nor manage to run the program, obviously)
What also do I have to change in Toolchain executables?
Thanks in advance
(To anyone who may not know how to install codeblocks for windows)
Remember, you'll want the mingw+setup executable.
NOTE: The codeblocks-13.12mingw-setup.exe file includes the GCC compiler and GDB debugger from TDM-GCC (version 4.7.1, 32 bit). The codeblocks-13.12mingw-setup-TDM-GCC-481.exe file includes the TDM-GCC compiler, version 4.8.1, 32 bit. While v4.7.1 is rock-solid (we use it to compile C::B), v4.8.1 is provided for convenience, there are some known bugs with this version related to the compilation of Code::Blocks itself.
GCC 4.7.1+ should support most c++11 functions
New GCC features compatibility list:
http://gcc.gnu.org/projects/cxx0x.html
To cut it short, 4.8.1 additionally supports:
Rvalue references for *this //4.8.1
//4.8.0
Alignment support
Inheriting constructors
Bidirectional Fences
Abandoning a process and at_quick_exit
Thread-local storage
@DPut
I don't think the "pure" 32-bit binaries of MinGW work. I tried it with TDM-GCC 32 bit (4.8.1) and it doesn't work, but if you use MinGW it works (I used i686-w64-mingw-32).
Slightly offtopic, why not use int myint1 = lexical_cast<int>(str1);?
I tried stoi with MinGW 4.8.1 and it doesn't work for me either. Why not get a different compiler that supports C++ 11? I used Visual C++ 2013 and tried stoi on there and it works. This is the code I tried:
1 2 3 4 5 6 7 8 9 10
#include <iostream>
#include <string>
int main()
{
std::string str = "12345";
int s_str = std::stoi(str);
std::cout << "The string is now an int: " << s_str << std::endl;
return 0;
}
@ franciscoat: Why not make your own conversion function? The one below works fine.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
#include <string>
#include <cstdlib>
int toint(std::string s) //The conversion function
{
return atoi(s.c_str());
}
int main()
{
std::string str = "12345";
int intx = toint(str); //Convert str to an integer
std::cout << "The string is now an int: " << intx << std::endl; //output it to the screen
return 0;
}
> I would like to use the function stoi, so I could convert a string to an int more easily.
> The problem is that everytime I try to use it, I get an error message saying: "'stoi' is not a member of 'std'".
Assuming that std::strtol() is available in the library, we can write a work-around: