Chapter 3 focuses on the string class and vector container.
1. Input operations for the string class:
. Read and ignore all leading blank characters (spaces, line breaks, tabulation );
. Read characters until blank characters are encountered again. The read ends,
For example:
String S1, S2;
Cin> S1> S2;
Cout <S1 <S2 <Endl;
Enter "Hello World"
The output will be "helloworld"
2. Any variable that stores the size () Operation of string must be of the string: size_type type. Do not assign the return value of size () to an int variable;
3. When a String object and a string literal value are connected together, at least one of the left and right operands of the + operator must be of the string type;
4. Although any integer value can be used as an index, it is best to use a string: size_type variable as an index;
5. c ++ programmers are used to choosing first! = Instead of <compile the loop judgment condition; (generic programming ?)
6. Use of the iterator:
For (vector <int >:: iterator iter = ivec. Begin (); iter! = Ivec. End (); ++ ITER)
* Iter = 0;
Purpose: assign a value of 0 to all elements in ivec;
7. const_iterator: its own value can be changed, but it cannot be used to change the value of the element to which it points;
Vector <string >:: const_iterator iter = text. Begin ();
+ ITER; // OK!
* Iter = "hello" // Error
(Note the difference with const-type iterator: the latter can only be used to change the elements it points to, rather than direct it to other elements)
8. The different_type value obtained by the two iterators. The two iterators must point to the same vector element;
9. Use Vector <int>: iterator mid = VI. Begin (1 + CI. Size ()/2) to initialize the iterator pointing to the intermediate element, which is efficient;
10. Any change to the length of vectore will invalidate the existing iterator.
11. The bitset class is used to save the yes/no information of a group of items or conditions. The sring class and bitset are converted in reverse order.