Home > Back-end >  STD: : string stored utf8 encoding problem
STD: : string stored utf8 encoding problem

Time:11-21

I use a string to store utf8 encoding format of the data, according to a newline to split the data is wrong, not all right, I'm through the find to find, to capture the substring,

CodePudding user response:

Find find sometimes will return a negative value, such as - 95-124, not 1

CodePudding user response:

You wide character is to be used for processing, string wstring, or directly with wstring
For example
 # include & lt; Iostream> 
# include & lt; Codecvt>
using namespace std;
Int main (void)
{
Wstring_convert & lt; Codecvt_utf8 & lt; Would be & gt;> Conv.
String s="who am I? "\ n is wide string;
Wstring ss=conv. From_bytes (s);//is converted into a wide string
Cout & lt;
Wstring ws=L "who am I? "\ n is wide string;//directly with wide string literals
Cout & lt;
return 0;
}


CodePudding user response:


Recommend unicode. His code range is consistent, not as utf8, one or two bytes to express one character at a time, unicode is always 2 bytes to express one character at a time,

CodePudding user response:

refer to the second floor qybao response:
do you want to handle with wide character, string wstring, or directly with wstring
For example
 # include & lt; Iostream> 
# include & lt; Codecvt>
using namespace std;
Int main (void)
{
Wstring_convert & lt; Codecvt_utf8 & lt; Would be & gt;> Conv.
String s="who am I? "\ n is wide string;
Wstring ss=conv. From_bytes (s);//is converted into a wide string
Cout & lt;
Wstring ws=L "who am I? "\ n is wide string;//directly with wide string literals
Cout & lt;
return 0;
}

Thank you, I have found the problem and solved
  • Related