About character encoding

Source: Internet
Author: User

A major concern is that STD: string is actually a structure similar to a vector <char>. It contains characters with ASCII 0.
It is not the end (otherwise there will be a problem with Unicode encoding). The actual length is obtained by length ().

There are several methods for string assignment and construction. You can refer to the document.
Example:
Char C [10] = "wer | \ t ";
C [4] = 0;
STD: String S = C;
Since C is a char * length, it can only be obtained by strlen, and strlen ends when it encounters 0, so data is lost.

To construct and assign values, the length must be passed in:
STD: String S (C, 6); // construct
S. Assign (C, 6); // value assignment, which includes the ending character 0
S. Assign (C, 5); // This does not include the end 0, for example, the serialized string of protobuf. You do not need to add 0 more.

About character encoding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.