Hopefully a simple question: cout seems to die when processing strings ending in a multibyte UTF-8 char, am I doing something wrong? This is from GCC (Mingw) to Win7 x64.
** Edit Sorry, if I wasn’t clear enough, I’m not interested in the missing glyphs or how the bytes are interpreted, but they just don’t appear right after the call to cout << s4 (there is no BAR). Any further cout after the first display does not contain any text!
#include <cstdio> #include <iostream> #include <string> int main() { std::string s1("abc"); std::string s2("…"); // … = 0xE2 80 A6 std::string s3("…abc"); std::string s4("abc…"); //In C fwrite(s1.c_str(), s1.size(), 1, stdout); printf(" FOO "); fwrite(s2.c_str(), s2.size(), 1, stdout); printf(" BAR "); fwrite(s3.c_str(), s3.size(), 1, stdout); printf(" FOO "); fwrite(s4.c_str(), s4.size(), 1, stdout); printf(" BAR\n\n"); //C++ std::cout << s1 << " FOO " << s2 << " BAR " << s3 << " FOO " << s4 << " BAR "; } // results: // abc FOO BAR abc FOO abc… BAR // abc FOO BAR abc FOO abc…
c ++ utf-8 cout
user657267
source share