Invalid behavior of size () and at () in a string class

I have this code:

string test("żaba");

cout << "Word: " << test << endl;
cout << "Length: " << test.size() << endl;
cout << "Letter: " << test.at(0) << endl;

The output is strange:

Word: żaba
Length: 5
Letter:  

As you can see, the length should be 4 and the letter: "ż".

How can I fix this code correctly?

+5
source share
2 answers

std::stringon non-Windows it is usually used to store UTF8 strings (which are the default encoding for most reasonable operating systems on this side of 2010), but it is a "dumb" container, which in the sense that it does not know or care about the bytes that you keep it. It will work for reading, storage and writing; but not for string manipulation.

IBM ICU: Unicode. C/++ * nix Windows, , , , , .

, ++, UTF8-CPP

+5

, , .

: , Unicode ( !).

, , " ", - - . , UTF-8 , , () 5 1 .


1) , string::size (= char s), .

+6

All Articles