Step-by-step learning C + +

Source: Internet
Author: User

According to "C + + Primer" Fifth Edition summarizes the learning experience.

In practice, it is not necessary to use the features of the C + + language comprehensively, but should be based on the actual situation of the project, appropriate trade-offs (such as dynamic type information, virtual inheritance, anomalies and other characteristics of the use, it is debatable), usually only encourage the use of a subset of the C + + language is enough.

Programming style, refer to Google C + + style guide.

The industry standard for the C + + language, from c++98 to the present c++11. C + + 's father Bjarne Stroustrup said that C + + supports four different programming styles: C-style, object-based, object-oriented, and generic.

The book mentions C + + advanced books, Scott Meyers's effective C + +, "C + + Concurrency in action" is the best choice for learning to develop concurrent programs with standard C + +, and Aboutspeaker's Linux multithreaded server programming.

The modern C + + language can generally be seen as a three-part composition:

1. Low-level languages, most of which inherit from C language

2. Modern high-level language features allow us to define our own types and organize large-scale programs and systems

3. Standard library, which leverages advanced features to provide useful data structures and algorithms

The defined data type not only defines the contents of the data elements, but also defines the operations that can be performed on such data.

The standard library defines 4 IO objects, the standard input object, the type IStream, and the name CIN.

The standard output object, type Ostream, is named cout.

The type is ostream and the name is Cerr, which is used to output warnings and error messages.

Type ostream, name clog, general message for output program runtime

All names defined by the standard library are in the namespace STD, and using the standard library is the premise of adding a using namespace std at the beginning of the program.

The C + + language prescribes short <= int <= long <= long long, and C + + specifies the minimum number of bytes for these types, which is determined by the machine system and the compiler together.

   1:  void test_read_many_number ()
   2:  {
   3:  /**< Read the number of patch input data * /
   4:     int sum = 0;
   5:     intvalue = 0;
   6:     whilevalue)/**<  uses CIN as a detection condition to detect the state of the stream if the flow is valid, Then the test succeeds .
   7:                                     When a file terminator is encountered or an invalid input is encountered (in this case, the invalid input is not an integer)
   8:                                     The state of the IStream object becomes invalid
   9:                                      under Windows system, CTRL + Z equals the input file Terminator
  :                                      under Unix systems, Ctrl+d equals the input file Terminator
  11:  
you can redirect                                   input and output to a file at the command line   
                                     "C++_primer.exe" <: /.. /input.txt > A.txt
                                    *   /  
  :          value;
  :  
  :     "The input sum is"<<sum <<std::endl;
  :  
  :  }

Note: Do not mix signed and unsigned types. Because when an expression has both an unsigned type and a signed type, the signed number is automatically converted to unsigned data when the operation occurs, causing an error.

For the storage of the string, the compiler adds a null character ' + ' at the end of each string, as a string end flag.

The type of object determines the operations that the object can participate in.

The reference is a different name for the object, and the reference itself is not an object.

When a const object is defined by the compile-time initialization method, the compiler will replace the value of the variable with the one used in the compilation process. for const int bufSize = 512, the compiler will find where the code is used in BufSize and replace it with 512来. By default, the const object is set to be valid only within this file. When a const variable of the same name appears in multiple files, it is equivalent to defining separate const variables separately in different files. You can add the extern keyword before a const-modified variable so that you can only define it once and share it in multiple files.

Step-by-step learning C + +

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.