I have been trying to convert an integer to a string, and I ran across the function to_string(). I tried to use it, but it doesn't recognize the command. This is what I have:
1 2 3 4 5 6 7 8 9 10
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
int var = 2;
string str = to_string(var);
cout<<str;
cin.get();
}
std::to_string is a quite new addition to C++. Are you using an up to date compiler? You might have to explicitly enable C++11 mode in the compiler. If you are using GCC you can do that by passing the flag -std=c++0x.
You have not said what is wrong. I can only guess that either you are using an old compiler that does not support the new C++ Standard, or you are using MS VC++ 2010. If you are using MS VC++ 2010 then you can make that your program will work:
It is in the <string> header but your compiler must be aware of/configured to use C++11. I think MSVC is enabled by default but with MinGW you need to pass "-std=c++11" to the compiler