The string class in C + +

Source: Internet
Author: User

The string class in C + +
1) is what:
A class of specialized string manipulation, very powerful, string cstring,qstring
2) The difference from char *
Char * is a pointer to the first address of the character array, then we provide a string.h, the header file declares a very string manipulation function, strlen, strcat, strcmp, strcpy ....
Stirng This class, we do not have to consider the memory mismatch and release, do not worry about the cross-border, because the predecessor in the encapsulation of string, has already taken almost all the circumstances,
3) Learning methods, learn to find three ways: MSDN, reference books, Baidu
4) header file #include <string>
And be sure to add using namespace std
Constructor for string
1) String str;
2) string str (5, ' a '); Initialize STR to 5 a
3) string str ("Awefgweg");
Str.empty () ==0, indicating that the string is empty
4) String str ("Aewgwea", 4); Assigns a value of AEWG to the string str
5) String str ("ABCDEFGH", 2,4); The string str is assigned a value of cdef,4 to indicate long
Degree
6) string str1 (str); Copy Construction
String class member function
1) str.size (); Find the number of STR sub-characters
2) Str.capaciyt () for STR capacity, an empty str, his capacity of 15, in order to improve efficiency, when more than 15 o'clock, at this time the capacity 15+16; when more than 31 o'clock, 15+16+16, ... and so on, the new 16 will be added each time it exceeds.
3) str.capacity (size_t); Change the size of STR, when it exceeds processing, increase by 16
4) Str.length (); string length, size and (1) are the same.
5) Str.resize (3); Intercept string
6) cout << str[3] << Endl; The third character in the output string str.

The string class in C + +

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.