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 + +