1 # include <iostream>
2 # include <string>
3 using namespace STD;
4
5 void main ()
6 {
7 char * Pc = "Lu Wei ";
8 cout <Pc <Endl;
9
10 char array [] = "mengliangliang ";
11 cout <array <Endl;
12
13 string str1 (PC );
14 string str2 (array );
15 cout <str1 <str2 <Endl;
16
17 string * str3 = new string;
18 int * A = new int (6 );
19 cout <* A <Endl;
20
21 int test = (* A) ++, 5 );
22 cout <test <Endl;
23}
24
The value of the entire comma expression is the value of the rightmost expression. The output result of test is 5.
1 void fun (char STR [])
2 {
3 // Process Code
4}
5
6 void main ()
7 {
8 string str5 = "Meng ";
9 char * pstr5 = str5; // Error
10 char a_char [] = str5; // Error
11
12 char * pstr6 = "Xiangshan ";
13 string str6 = pstr6; // right
14 char a_ch [] = pstr6; // Error
15 fun (pstr6); // right
16
17 cout <pstr6 [0] <Endl; // right
18 cout <str5 [0] <Endl; // right
19}
20
Interaction initialization between string and char *: char * can be used for string initialization *. String cannot be used for char * initialization.
String variable name and char * pointer name can be used as an array name.