c ++ learning basic learning record (a)
c ++ language is the expansion and improvement of object-oriented programming language based on the C language. So mostly c ++ basics similar to the C language, learning the C language, the foundation can quickly spend learning c ++ language.
1.c ++ data types, modifiers, variables and constants
(1) Data Types
c ++ data types are basic built-in types, typedef statement, enumerated types, etc.
· Basic built-in types
Types of | Keyword |
---|---|
Boolean | bool |
Character | char |
Integer | int |
Float | float |
Dual Float | double |
Untyped | void |
Wide character | wchar_t |
· Typedef statement
typedef may take a new name for an existing type. Such as
\\typedef int abc;
abc h=1;
· Enumerated type
\\enum 枚举名{x,x,x,x}枚举变量;
c ++ base data type in C language is the same, except wchar_t, character constants are enclosed in single quotes. If the constants L (only when capitalized) beginning indicates that it is a wide character constants (e.g. L'x '), at which time it must be stored in a variable of type wchar_t. Otherwise, it is a narrow character constants (e.g., 'x'), where it can be stored in simple variable of type char. .
(2) Modifiers
char, int, double base type may be used signed, unsigned, short, long modified modifier. Wherein the modifier is signed, unsigned, long, short modification int; signed, unsigned char modification; Long modified double.
(3) constant and variable
c ++ as in the definition of methods and definitions of constants and variables. There are also global variables and local variables
2.c ++ basic input and output, and comments
c ++ header files
cost
flow cout << insert used in conjunction operator, output variables, << be used multiple times in a statement, such as:
\\cout << "hello world"<< endl; #endl表示换行
China
cin and extracting operator >> combination, extracting operator >> can be used repeatedly in a statement
Palau
cerr is non-buffered and immediately outputs
clog
clog is buffered, only the buffer fills or output buffer will refresh
Note
c ++ // comment line to order / and / multi-line comments.
3.c ++ references
c ++ pointer referenced similarly. However, there are three different references:
· Null reference does not exist. Reference must be connected to a legitimate memory.
· Once the reference is initialized to an object, it can not be directed to another object.
· Reference must be initialized when created.
It is a symbol reference & usage similar to the following:
\\int i;
int& r=i;