The difference between C string and C + + string __c++

Source: Internet
Author: User
In the C language, strings are treated as an array of characters. That is, a C string is a char arrary[max_size]; an array of characters. The string in C + + is string class, which declares the form string strobject. variable is an object. It's just that he is a string class provided by the C + + standard library that implements the same effects as a user-defined class. The C string string can be in string array char array[max_size]; with the string variable char *p; Two ways to store. Ends the symbol with ' I ' as a string. Strlen is the string Terminator ' "," and sizeof is in the character array and character variable operation result is different, cause the principle is different.
STRCMP,STRNCMP, the connection uses strcat, cannot str1+str2, strncat,strcpy, stncpy; STRCHR (STR1, ch); Find the first occurrence of CH in str1, return the pointer variable and C + + string is a class and is an object. The Terminator is NPOs, or-1, and this is mostly the case when you use a member function of C + + string without specifying the number of characters.
+ replaces the strcat length and size with the strlen
Functions such as append, compare, Substr,find, find_firt_of can be directly = without strncpy. Insert, replace, at, Erase, clear, swap, and the implementation of the iterator function.
******************************** above content is sorted from original text ***********************************

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.