News for hackers. Stuff that matters.
Re:Formatting Text in C++: The Old and the New Ways by 38 on Saturday September 16, 2023 @03:52PM (#37538061)

    unsigned char str[]{3,4,5,6,0};
    std::stringstream ss;
    ss << "str=" << str;
    std::string text = ss.str();
> The content of text will be "str=♥♦♣♠".

no, it wont. if you are on an old Windows with code page 437 then sure. but on any sane UTF-8 system, you're just going to get some binary data.

1. https://wikipedia.org/wiki/Code_page_437

Re:Formatting Text in C++: The Old and the New Ways by mrcode007 on Saturday September 16, 2023 @04:06PM (#37538195)
Thanks for finding this out as a codepage issue. The implementation of the operator<< will indeed call ostream::widen() to expand character into a locale dependent equivalent.