The next day regain c ++ (4): composite type

1, the definition: type array name [number of elements] = {elements 1, ..., element n}, or direct assignment: array name [element location] = value;

2, part of the initialization, other all 0, a definition can be 0, 0 thus obtained array (or just a {}, had nothing else)

3, the number of array elements  int NUM = the sizeof array name / the sizeof (data type); 

4, char array, string '\ 0' end

. 5,  char Test [] = " ABCDE "  directly define such string

6,  cout << " abc " " de ";  this is legal

. 7,   #include <CString>  can then be used   strlen () // string length  , not here '\ 0' length occupied

8,  cin >> name of the array; 

. 9,  cin.getline (array name, length);  reads a line of data, ignoring spaces

10,  . CIN GET () to remove the influence newline  Example:  (CIN >> array name). GET (); 

. 11,  #include < String >  then add a new data type --string, can be directly assigned splicing

12, the original string need  strcpy ()  to copy, and  strcat ()  splice

13, string data types can call .size () method to get the string length

14, the structure associated

 

After defining direct  inflatable variable name = {variable 1, ..., variable n};  line (c ++ struct is omitted), when calling  the variable name variable n. 

15, the general outer structure stated, located at the front

16, the structure is empty, the initial value is 0

17, the structures can be assigned a = b

18, can be directly connected to the structural braces {} = variable 14; complete the definition

19, an array of structures

inflatable variable name [ 2 ] = { 
    {variable 1, ..., n-variable}, 
    {variable 1, ..., variable} n- 
};

20, union definition structure similar union, but each time only one type of memory, is used to save memory

21, the enumeration: enum {new types of name = value 1 ..., the value n};

22, & fetch address (pointer), address-* (pointer) value

23, the pointer definition example: int * a, b;

24,  the type name of the pointer * = new new type  it will allocate a suitable address for storing the type of data, then the * name of the pointer type constant =

25, delete the name of the pointer (pointer to be associated with the new)

26, dynamic arrays

* Pointer Type name = new new type [length] ---- Delete [] pointer name

Pointer name [position] direct call, play equivalent to the array

27, pointer pointer name = name + 1 is equivalent to all the right elements, then delete fail

28, * (name pointer + i) = pointer name [i]

29, new structure of the two kinds of targeting methods herein :( doubtful)

1、cin.get(ps->name, 20)  cin>>ps->name
2、cin>>(*ps).name

Guess you like

Origin www.cnblogs.com/dai-yu/p/12193875.html