Search code examples
c++mingwcodeblocksmingw-w64tdm-gcc

C++ - to_string not working across multiple compilers (MinGW, MinGW64, TDM GCC) in Code::Blocks in Windows


I am getting desperate. On Windows 7 using Code::Blocks, I've installed about a half-dozen variations of MinGW / TDM-GCC, but I can't get to_string to convert my int to a string, e.g.:

std::cout << std::to_string(1) << ' - one' << std::endl;

outputs 1544173669

I've seen various bug reports about to_string not working in earlier versions of MinGW (anywhere from before v4.7 - 4.9), but I've tried the latest versions to no avail. I've followed these instructions to install the latest TDM-GCC, changing the tool-chain and debugger settings appropriately.

All I am asking for is some kind of explanation and solution as to why this is not working. I can provide any further information as needed.


Solution

  • It actually printed it correctly for you, plus of cause, your Multi-character constant (which is implementation defined)...

    std::cout << std::to_string(1) << ' - one' << std::endl;
    

    You use double quotes to represent a string, what you wanted to write perhaps is:

    std::cout << std::to_string(1) << " - one" << std::endl;