Unicode string indexing in C++

后端 未结 5 1606
刺人心
刺人心 2020-12-30 15:05

I come from python where you can use \'string[10]\' to access a character in sequence. And if the string is encoded in Unicode it will give me expected results. However when

5条回答
  •  生来不讨喜
    2020-12-30 15:38

    To access codepoints individually, use u32string, which represents a string as a sequence of UTF-32 code units of type char32_t.

    u32string ramp = U"ÐðŁłŠšÝýÞþŽž";
    cout << ramp << "\n";    
    cout << ramp[5] << "\n";
    

提交回复
热议问题