1
#include
<
iostream
>
2 #include < vector >
3 #include < string >
4 using namespace std;
5
6 int main()
7 {
8 const char * p = " hello " ;
9 int count = 0 ;
10 while ( * p)
11 {
12 cout << * p << endl;
13 count ++ ;
14 p ++ ;
15 }
16
17 const char ca[] = { ' h ' , ' e ' , ' l ' , ' l ' , ' o ' };
18 const char * cp = ca;
19 while ( * cp)
20 {
21 cout << * cp << endl;
22 cp ++ ;
23 }
24
25 vector < string > svec;
26 string str;
27
28 cout << " Enter strings: " << endl;
29 while (cin >> str)
30 {
31 svec.push_back(str);
32 }
33
34 char ** parr = new char * [svec.size()];
35
36 size_t ix = 0 ;
37 for (vector < string > ::iterator iter = svec.begin(); iter != svec.end(); iter ++ , ix ++ )
38 {
39 char * p = new char [( * iter).size() + 1 ];
40 strcpy(p, ( * iter).c_str());
41 parr[ix] = p;
42 }
43
44 for (ix = 0 ; ix != svec.size(); ++ ix)
45 {
46 cout << parr[ix];
47 delete [] parr[ix];
48 }
49
50 delete [] parr;
51
52 cin. get ();
53 return 0 ;
54 }
2 #include < vector >
3 #include < string >
4 using namespace std;
5
6 int main()
7 {
8 const char * p = " hello " ;
9 int count = 0 ;
10 while ( * p)
11 {
12 cout << * p << endl;
13 count ++ ;
14 p ++ ;
15 }
16
17 const char ca[] = { ' h ' , ' e ' , ' l ' , ' l ' , ' o ' };
18 const char * cp = ca;
19 while ( * cp)
20 {
21 cout << * cp << endl;
22 cp ++ ;
23 }
24
25 vector < string > svec;
26 string str;
27
28 cout << " Enter strings: " << endl;
29 while (cin >> str)
30 {
31 svec.push_back(str);
32 }
33
34 char ** parr = new char * [svec.size()];
35
36 size_t ix = 0 ;
37 for (vector < string > ::iterator iter = svec.begin(); iter != svec.end(); iter ++ , ix ++ )
38 {
39 char * p = new char [( * iter).size() + 1 ];
40 strcpy(p, ( * iter).c_str());
41 parr[ix] = p;
42 }
43
44 for (ix = 0 ; ix != svec.size(); ++ ix)
45 {
46 cout << parr[ix];
47 delete [] parr[ix];
48 }
49
50 delete [] parr;
51
52 cin. get ();
53 return 0 ;
54 }