Read C ++ primer2 again

Source: Internet
Author: User

1. This concept must be distinguished by pointer assignment and pointer assignment.

Assign values by pointer: indicates the value of the memory area pointed to by the update pointer.

Assign a value to the pointer: changes the address to which the Pointer Points. The Pointer Points to another address.

Int A = 3, B; int * P = & A; * P = 4; // assign a value to the pointer through the pointer P = & B; // assign a value to the pointer

Pointer to const object and const pointer

Pointer to the const object: indicates that the Pointer Points to the const object. You cannot use this pointer to modify the object to which it points, but you can update the object address pointed to by the pointer.

Const pointer: indicates that the pointer is const. You cannot change the pointer address. You can update the object pointed to by the pointer.

Const char * P = new char [100]; // This memory cannot be used, and char * const P = new char [100] cannot be modified; // This memory can be used

2d array Initialization

① Each dimension uses a {} ② initialization based on the position of the element.

Int A [3] [4]; A [2] is the name of the array in the last row.

Define a new type for the array:

Typedef int int_array [4]; // when you use int_array, it indicates creating an array int_array A with a dimension of 4; // It indicates creating an array with a dimension of 4.

Typedef intint_array [4]; // when you use int_array, it indicates creating an array with a dimension of 4

Int_array A; // indicates creating an array with a dimension of 4.

The const function must be modified in both the description and definition of the function. Otherwise, a compilation error occurs.

Inline can be modified in the class declaration or definition.

There are two ways to define a Class Object

Declare that A is a class

①;

② Class;

The function can be reloaded based on whether the function is a const function.

The data member of the mutable modified class can be modified by the const member function.

Mutable int;

10. iostream istream reads ostream from stream output iostream from Stream Input and Output from stream, inherits istream and ostreamfstreamifstream from File Read, inherit from istreamofstream write to file, inherit from ostreamfstream to read and write files, inherit from iostreamsstreamistringstream to read from string inherit from istreamostringstream write to string, inherit from ostreamstringstream read and write to string, inherit from iostream

The following figure details the relationship between them:

Ifstream file (file_name); = ifstream file; file. Open (file_name)

Ofstream file (file_name); = ofstream file; file. Open (file_name );

Fstream file. Close () // close the object

There are also file opening methods such as in, out, and app.

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.