3 ms·
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=♥♦♣♠".
by 38 3y ago
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 https://wikipedia.org/wiki/Code_page_437
- mrcode007 3y agoThanks 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.