1.string
1 #include <iostream>
2 #include <string>
3 using namespace std ;
4
5 int main()
6 {
7 string s = "hello", s2("world");
8 cout << s.size() << endl;
9 string s3 = s.substr(1,3);
10 cout << s2 << endl;
11 cout << s3 << endl;
12 string s4 = s + " " + s2;
13 cout << s4 << endl;
14
15 s4[0] = 'H';
16 s4[6] = 'x';
17 cout << s4 << endl;
18 int pos = s4.find("orl");
19 cout << pos <<endl;
20 s4.insert(3, "ABCDE");
21 cout << s4 << endl;
22
23 for(int i = 0; i < s4.size(); i++)
24 {
25 cout << s4[i] << "-";
26 }
27 cout << "\n";
28 }
2.vector
1 #include <iostream>
2 #include <string>
3 #include <vector>
4 using namespace std;
5
6 int main()
7 {
8 vector<int>v;
9
10 v.push_back(25);
11 v.push_back(36);
12 v.push_back(3);
13 v.push_back(5);
14 v.push_back(6);
15 v.push_back(7);
16 for(int i = 0; i < v.size(); i++)
17 {
18 cout << v[i] << '\t';
19 }
20 cout << '\n';
21 v.resize(2);
22 v.pop_back();
23 for(int i = 0; i < v.size(); i++)
24 {
25 cout << v[i] << '\t';
26 }
27 cout << '\n';
28 return 0;
29 }