C + + Primer Learning Summary 3rd Chapter string, vector and array

Source: Internet
Author: User

3rd chapter strings, Vectors and arrays


1. How do I read a whole line of content with a string?

You can use Getline (cin,s). Of course getline () can also be used as a while loop to read input judgment conditions.

2. String literals and literal values of strings are added

Since the + method is left-to-right, so long as the two values are guaranteed to be added, at least one of the two sides of the + sign is a string on the line.

3. String can be added not only to the string literal, but also to An array of strings that end with the ' + ' character .

4. Note the initial value of the following array:

If both A and B arrays are global:

5. Complex array declarations

6. Note the operation of the following pointers:

7. Note the following two different output results:

Because STR actually points to a string constant array in string s, the contents of STR change naturally if the contents of the array are changed. So look at the following results:

Why does it still output ABCDE? Because the original string array can only hold 5 characters, now the new string has 6 characters, then the string class will request a new large enough space to re-save "ABCDEF", and the previous character array str content is unchanged, so if we also output str, is actually outputting the contents of the old string array.

8. How to initialize vectors with arrays in c++11

9. Multidimensional arrays in C + + are just arrays of arrays

When auto and Decltype infer an array name, the result is different:

Auto infers a pointer type , and Decltype infers an array type .

C + + Primer Learning Summary 3rd Chapter string, vector and array

Related Article

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.