I compiled on Ubuntu a program that was developed for (and works on) Windows. On Ubuntu, I see this code:
string s = values_[9];
cout << s << endl;
cout << s << "x\n";
producing this output:
high
xigh
The expected output for the second line is “highx”. I know that the value of values_[9] is originally read from a file (written on Windows). Printing other strings seems to work normally.
What’s going on here?
Run the command with its output piped through
cat -A. Probably either the value ofs, or the output produced byendlis giving you a'\r'character, which typically sends the cursor back to the beginning of the line.EDIT: On further thought, the stray
'\r'is almost certainly ins, not in the output produced byendl. I had thought there might be some funny locale stuff going on, but havingsequal to"high\r"explains the symptoms.EDIT2: If your system doesn’t have
cat -A(it’s a GNU extension), trycat -vor, if you’re desperate,od -c.