Chapter one — The Beginning

1.1 Compiling Commands

GNU compiler g++ source file -o generates file name vs2010 cl /EHsc source fileCopy the code

1.2 INPUT and Output

Iostream contains istream(input stream) and ostream(output stream). Cin cout cerr clog Enter two integers (within the int range) and print them together with #include <iostream> using namespace STD; Int main() {// cout<<"Enter two numbers: "<<endl; // store input int v1=0,v2=0; // Assign the input cin>>v1>>v2; / / output and cout < < "The sum of < < v1" < < "and" < < "is" < < < < v2 v1 + v2 < < endl; return 0; } All names defined by the library are in the namespace STDCopy the code

1.3 annotations

Single line comment: // Comment content multi-line comment: /\* Comment content */Copy the code

1.4 the control flow

1.4.1 while statement: / * author: Mr. Lin, the compiler: online compiler rookie tools | date: 2021/2/24 input: no output: the output 1 + 2.. */ #include<iostream> using namespace STD; Int main(){sum=0; Int count=1; While (count<=10) {sum +=count; count++; Cout <<"Sum of 1 to 10 is: "<< Sum <<endl; // return 0; } Run resultCopy the code

1.4.2 for statement: / * author: Mr. Lin, the compiler: online compiler rookie tools | date: 2021/2/24 input: no output: the output 1 + 2.. */ #include<iostream> using namespace STD; Int main(){sum=0; For (int I =1; i<=10; i++) sum+=i; Cout <<"Sum of 1 to 10 is: "<< Sum <<endl; // return 0; } Run resultCopy the code