Learn more C ++ primer (3)-standard library type

Source: Internet
Author: User

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.

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.