Chapter One C + +: function return value, GNU compiler command

Source: Internet
Author: User

function return value

    • The return value type must be the same as the return type of the function

    • For the main function, the return value must be of type int. In most systems, the return value of the main function is a status indicator. A return value of 0 indicates that the main function completed successfully, and a non-zero return indicates an error occurred.

GNU compiler command

    • VI: New file, I: Edit; Esc exit edit; Wq/zz: Save and exit

    • g++ xx.cc-o XX: Compiles the xx.cc and generates the executable file XX.

      ./XX: Run executable file XX

    • echo $?: After executing the program, access the main function return value to get the state.

Input/Output iostream

iostream library, input stream (istream) and output stream (ostream)

    • Standard input: CIN

    • Standard output: cout

    • Cerr: Standard error, used to output program warnings and error messages.

    • Clog: General information used to generate program execution.

1. Pre-processing instructions: #include

2. Write to stream

    • Output operator: <<, each output operator instance accepts two operands, the left operand must be a Ostream object, and the right operand is the value that needs to be output.

    • Operator (manipulator) Endl: writes it to the output stream, has the effect of a newline output, and refreshes the buffer associated with the device (buffer) so that the user can immediately see the output written to the stream.

3. Use the names in the standard library, such as Std::cout,std::endle

    • Indicates that cout and Endl are defined in the namespace (namespace) std

    • Scope operator (scope operator,:: operator)

4. Read the inflow, such as Std::cin >> v1 >> v2;

    • Input operator:>>

5. Notes

    • Comment Qualifier (/**/) cannot be nested

    • The best way to annotate snippets is to use single-line annotations (//)

Read in Unknown purpose input

    • Sums the user-specified set of numbers until the input is finished.

int val;//read until End-of-file*/while (Std::cin >> val) {    ...}
    • Using the IStream object as a condition, the result is the state of the test flow. If the stream is valid, the test succeeds, and if a file terminator (End-of-file) is encountered or the input is invalid (if the read is not an integer value, the IStream object is not valid), which results in a test failure.

    • Enter the file terminator from the keyboard: Unix file Terminator ctrl+d, the equivalent of VC + + in Windows. C file (ctrl+z+enter) * *. Note: EOF is not required in the code.

    • The variables defined in the For loop can only exist in the for loop and cannot be used after the loop has ended.

    • Edit-compile-debug, after modifying an error or a small subset of errors, recompile the code immediately.

Class

    • The header file of the standard library is enclosed in angle brackets <>, and the header file of the nonstandard library is enclosed in double quotation marks.

    • member functions (member function), also known as class methods. Call the member function, using the dot operator (.).

    • Call Operator: ().

Using file redirection

$ addaitems <infile> outfile
    • The addition program has been compiled into an additems executable file, which reads the records from a file named infile and outputs the results to a file named outfile.

Terms

    • argument (argument): The value passed to the called function

    • BLOCK: A sequence of statements enclosed in curly braces

    • main function: The function that the operating system calls when executing a C + + program. Each program has and has only one main function main

    • Manipulator (manipulator): An object, such as Std::ebndl, that "manipulates" the stream itself when reading or writing.

    • member function (member functions), Method (methods): Synonyms, refers to actions defined by a class

    • namespace (namespace): The mechanism by which the name defined by the library is placed in a single place. Namespaces help to avoid unintentional naming conflicts. The name defined by the C + + standard library is in the namespace Std.

    • String literal (string value): A sequence of characters enclosed in double quotation marks

    • Uninitialized variable (uninitialized variable): class type If no initial value is specified, it is initialized in the manner defined by the class. A built-in type variable that is defined inside a function is not initialized by default unless there is an initialization statement displayed.

Reference: C++primer Fifth Edition

Related articles:

Chapter II C + +: variables and basic types

Chapter III C + +: string strings, vector vectors and arrays

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.