to_string is not a member of std, says g++ (mingw)

to_string' is not a member of 'std visual studio
to_string is not a member of 'std dev c++
to_string is not a member of std g++
to_string' is not a member of 'std' arduino
to_string' was not declared in this scope c
ubuntu to_string is not a member of std
std::to_string
to_string is not a member of std c 14

I am making a small vocabulary remembering program where words would would be flashed at me randomly for meanings. I want to use standard C++ library as Bjarne Stroustroup tells us, but I have encountered a seemingly strange problem right out of the gate.

I want to change a long integer into std::string so as to be able to store it in a file. I have employed to_string() for the same. The problem is, when I compile it with g++ (version 4.7.0 as mentioned in its --‍version flag), it says:

PS C:\Users\Anurag\SkyDrive\College\Programs> g++ -std=c++0x ttd.cpp
ttd.cpp: In function 'int main()':
ttd.cpp:11:2: error: 'to_string' is not a member of 'std'

My program that gives this error is:

#include <string>

int main()
{
    std::to_string(0);
    return 0;
}

But, I know it can't be because msdn library clearly says it exists and an earlier question on Stack Overflow (for g++ version 4.5) says that it can be turned on with the -std=c++0x flag. What am I doing wrong?


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.

error: 'to_string' is not a member of 'std' : cpp_questions, error: 'to_string' is not a member of 'std' The version of MinGW I'm using is 4.9. behind "Have g++ follow the C++11 ISO C++ language standard [-std=c++11]" I go to the MinGW folder and now it says I have GCC5 series and GDB 7.9  to_string is a current issue with Cygwin. Here's a new-ish answer to an old thread. A new one did come up but was quickly quashed, Cygwin: g++ 5.2: ‘to_string’ is not a member of ‘std’.


#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++, PS C:\Users\Anurag\SkyDrive\College\Programs> g++ -std=c++0x ttd.cpp ttd.cpp: In function 'int main()': ttd.cpp:11:2: error: 'to_string' is not a member of 'std'. to_string is a current issue with Cygwin. Here's a new-ish answer to an old thread. A new one did come up but was quickly quashed, Cygwin: g++ 5.2: ‘to_string’ is not a member of ‘std’. Too bad, maybe we would have gotten an updated answer. According to @Alex, Cygwin g++ 5.2 is still not working as of November 3, 2015.


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;
}

Compiling, template<typename T> std::string to_string(const T& n) { std::ostringstream ss; ss << n; to_string is not a member of std, says g++ (mingw). Sent: Monday, May 08, 2017 5:13 PM To: mingw-users@ Subject: Re: [Mingw-users] 'to_string' is not a member of 'std' -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On May 5, 2017, Keith Marshall wrote: >On 08/05/17 18:23, Eli Zaretskii wrote: >> I hit this problem today while building a pretest of GDB 8.0 with >> MinGW.


Use this function...

    #include<sstream>
    template <typename T>
    std::string to_string(T value)
    {
      //create an output string stream
      std::ostringstream os ;

      //throw the value into the string stream
      os << value ;

      //convert the string stream into a string and return
      return os.str() ;
    }

    //you can also do this
    //std::string output;
    //os >> output;  //throw whats in the string stream into the string

json.hpp:5746:32: error: 'to_string' is not a member of 'std' · Issue , json.hpp:5746:32: error: 'to_string' is not a member of 'std' #136 I'd recommend not adding std::to_string, partially because of what @gregmarr said. Instead C:\​Program Files (x86)\CodeBlocks16\MinGW\bin>g++ --version While with that issue, -mcrt=clib2 helps, with issue 57, it didn't. Also, clib2 is of no use when you port something big sadly, as there is many other places where newlib should be used instead.


to_string is a current issue with Cygwin

Here's a new-ish answer to an old thread. A new one did come up but was quickly quashed, Cygwin: g++ 5.2: ‘to_string’ is not a member of ‘std’.

Too bad, maybe we would have gotten an updated answer. According to @Alex, Cygwin g++ 5.2 is still not working as of November 3, 2015.

On January 16, 2015 Corinna Vinschen, a Cygwin maintainer at Red Hat said the problem was a shortcoming of newlib. It doesn't support most long double functions and is therefore not C99 aware.

Red Hat is,

... still hoping to get the "long double" functionality into newlib at one point.

On October 25, 2015 Corrine also said,

It would still be nice if somebody with a bit of math knowledge would contribute the missing long double functions to newlib.

So there we have it. Maybe one of us who has the knowledge, and the time, can contribute and be the hero.

Newlib is here.

error: 'to_string' is not a member of 'std' · Issue #58 · sba1/adtools , ppc-amigaos-g++ -athread=native -std=c++11 test2.cpp. And have : test2.cpp:7​:36: error: 'to_string' is not a member of 'std' std::string pi = "pi  24 August 2012, 11:16 UTC This patch enables the following list of C++11 functions and templates in the std namespace: stoi, stol, stoul, stoll, stof, stod, stold, to_string, to_wstring This assumes you are using the official MinGW distribution.


MinGW, g++ to_string.cpp -o to_string.exe -std=c++0x to_string.cpp: In function 'int main(​int, char**)': to_string.cpp:5:23: error: 'to_string' is not a member of 'std' .com/​questions/12975341/to-string-is-not-a-member-of-std-says-so-g. Also, it is not allowed for user code to add things to the std namespace except in very specific circumstances. I think that adding std::to_string should be done by the application, not the library, as the reason it's missing is the application's choice of which NDK standard library to use, not an inherent platform limitation.


error: 'to_string' is not a member of 'std' ^, Hello, Trying to convert string to int in QT: #include std::string g = std::to_string(4); Compiler shows error: error: 'to_string' is not a member of  Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.


to_string is not a member of std, says g++ (mingw), I want to use standard C++ library as Bjarne Stroustroup tells us, but I have encountered a to_string is not a member of std, says g++ (mingw). Note this is not an issue with the code, but rather with the compiler itself. On Android, see above to build with a newer environment. For MinGW, please refer to this site and this discussion for information on how to fix this bug. For Android NDK using APP_STL := gnustl_static, please refer to this discussion.