A simple procedure

  • Function: contains 4 parts: return type, function name, parameter list, function body. The function body is a statement block.
  • Main function: Each CPP program has one and only one main. The OS calls main to run the program. The return type of the main function must be int, which is used to indicate status, with 0 indicating a successful return and non-0 values defined by the system and often used to indicate error types.
  • Type: A type defines not only the contents of data elements, but also the operations that can be performed on such data. That is, type = Content + operation

Compile and run the program

  • Check the return value: you can check the return value of the main function by using echo $? Windows echo %ERRORLEVEL%
  • GNU compilation: g++ -o prog1 prog1.cc, where -o prog1 specifies the output file name, or a.out if not specified. C++ 11 can also be turned on by -std=c++11
  • VS compilation: CL /EHsc prog1.cpp, where /EHsc is the compiler option to turn on standard exception handling. The executable file name generated by VS is the same as the first source file name, with the suffix.exe
  • Warning: -wall in GCC, /W4 in VS
  • CMakeLists: www.cnblogs.com/sddai/p/103…

The control flow

While statement

  • While do… While executes before judging
  • The condition is an expression that returns true or false
  • A statement block is a type of statement and can be used anywhere a statement can be used
  • The difference between I ++ and ++ I: I ++ increments I after statement execution, and ++ I increments I before statement execution. Also, in terms of speed, ++ I is faster for class types because I ++ returns the value of I and ++ I returns a reference to I.

Sales_item class

  • Angle brackets <> are applied to headers that contain files from the library, and double quotation marks “” are applied to headers that do not belong to the library.
  • File redirection: Most systems use A.outfile to take infile content as standard input and write standard output to outfile