C ++ array output

C ++ output data array are two cases: the non-character array and the character array

When the character array variable is defined, using the array name cout <<; array system will be output as a string, such as:

1 char str[10]={'1','2'};
2 cout << str <<endl ; //输出12

If you want to output a character array address, you need to cast , such as:

. 1  char str [ 10 ] = { ' . 1 ' , ' 2 ' };
 2 COUT << static_cast < void *> (str) << endl; // press str hexadecimal address output, such as: 0012FF74

When defining a non-variable character within the array, using the array name cout <<; array name as the system will output an address, such as:

. 1  int a [ 10 ] = { . 1 , 2 , . 3 };
 2 COUT a << << endl; // press a hexadecimal value of the output (address) 0012FF58

If the contents of the array needs to be output, you need to use the cycle, the output of the array by one element, such as:

. 1  int A [ 10 ] = { . 1 , 2 , . 3 }; // initialize the first three elements, the remaining elements of 0 
2  for ( int I = 0 ; I < 10 ; I ++ )
 . 3      COUT << A [I] < < "  " ;
 . 4 COUT << endl; // output: 1230000000

Note: Other uses for loop

1 for (auto i :a)
2     cout<<i<<endl;

Original Source: https: //zhidao.baidu.com/question/28706144.html

Guess you like

Origin www.cnblogs.com/ZaneEli/p/11089227.html