1

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.

Gerald
  • 521
  • 1
  • 6
  • 16

2 Answers2

3

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;
Community
  • 1
  • 1
WhiZTiM
  • 21,207
  • 4
  • 43
  • 68
  • 1
    There's no UB here. `' - one'` is implementation-defined and need not give a warning. – M.M May 19 '16 at 03:33
  • 1
    @M.M, Ouch, you are right. No UB. corrected! ... regarding the warning, Its safer for users that compilers emit a warning or permit you to explicitly suppress it. Example, like with the way they (gcc and Clang) do with expressions like `if(x = 5)`; suppressed by `if((x = 5))`. On a few occasions, I have been saved hours of debugging subtle bugs by such warnings . For Implementation-defined Behavior - If we are `pedantic` with portable C++... ...Of cause, its more of a debatable issue here, since its not a mandate.... – WhiZTiM May 19 '16 at 09:34
2

I'm assuming you mean " - one".

' ' are for single characters only.

Clay Brooks
  • 182
  • 1
  • 11