c++ – to_string is not a member of std, says g++ (mingw)
c++ – to_string is not a member of std, says g++ (mingw)
This is a known bug under MinGW. Relevant Bugzilla. In the comments section you can get a patch to make it work with MinGW.
This issue has been fixed in MinGW-w64 distros higher than GCC 4.8.0 provided by the MinGW-w64 project. Despite the name, the project provides toolchains for 32-bit along with 64-bit. The Nuwen MinGW distro also solves this issue.
#include <string>
#include <sstream>
namespace patch
{
template < typename T > std::string to_string( const T& n )
{
std::ostringstream stm ;
stm << n ;
return stm.str() ;
}
}
#include <iostream>
int main()
{
std::cout << patch::to_string(1234) << n << patch::to_string(1234.56) << n ;
}
do not forget to include #include <sstream>
c++ – to_string is not a member of std, says g++ (mingw)
As suggested this may be an issue with your compiler version.
Try using the following code to convert a long
to std::string
:
#include <sstream>
#include <string>
#include <iostream>
int main() {
std::ostringstream ss;
long num = 123456;
ss << num;
std::cout << ss.str() << std::endl;
}
Related posts on c++ :
- c++ – error: lvalue required as unary & operand
- c++ – No matching member function for call to ‘push_back’ error
- c++ – glm rotate usage in Opengl
- c++ – Error: Expression must have integral or unscoped enum type
- c++ – Argument list for class template is missing
- c++ – qualified-id in declaration before ( token
- Is it possible to decompile a C++ executable file
- c++ – Pointer to incomplete class type is not allowed
- c++ – How can I create objects while adding them into a vector?