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.
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;
This portion: std::to_string(1)
printed 1
And this portion: ' - one'
printed 544173669
for you.
That gave you the output you got: 1544173669
.
Your compiler is supposed (assuming -pedantic
) to warn about the expression ' - one'
. See Multi-character constant warnings and What do single quotes do in C++ when used on multiple characters?
You use double quotes to represent a string, what you wanted to write perhaps is:
std::cout << std::to_string(1) << " - one" << std::endl;