The difference between C++ and C language
C language process-oriented programming language:
- When C language solves a problem, it is to follow the problem-solving steps, encapsulate functions, and then call the functions in turn according to the steps.
C++ object-oriented programming language:
- C++ is produced (inherited all the grammatical points of C language, and added object-oriented grammar rules on this basis), C++ is a superset of C language. C++ can be used for both process-oriented programming and object-oriented programming.
Language | C | C++ |
---|---|---|
file type | .c | .cpp |
Header file suffix | xxx.h | .h or .hpp |
System header file | < stdio.h > | < cstdio> |
Citation method | < string.h > | < cstring > |
translater | gcc | g++ |
Install g++
sudo apt-get install g++
Input and output in C++
-
It is very troublesome to output the output of C language, it needs to use the format output symbol
C++ output is very simple (C++ can also use printf())
== cout<<variable name ==
Note:-
The first one: \n --"Replace with endl
-
The second one: cout can continuously output cout<<variable 1<<variable 2<<variable 3<<endl;
-
The third: C++ encounters a char * pointer, and it is treated as a string by default, not as an address.
The solution is to force transfer
-
char buf[10]="hello";
cout<<buf<<endl; //字符串
cout<<(int *)buf<<endl; //地址
- Enter
cin>>the name of the variable.
Note: cin is not the address of the variable, but the name of the variable
C++ experience
The g++ compiler is very strict. A little grammatical error will appear, and a lot of information will be prompted. You only need to view the previous information, and the latter information does not need to be read (and can’t understand)