forked from tushargosavi/cpp-learn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtest.cpp
41 lines (31 loc) · 1003 Bytes
/
vtest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;
int main(int argc, char *argv[])
{
vector<string> sentence;
sentence.reserve(5);
sentence.push_back("Hello");
sentence.push_back("How");
sentence.push_back("Are");
sentence.push_back("You");
sentence.push_back("?");
copy(sentence.begin(), sentence.end(),
ostream_iterator<string>(cout, " "));
cout << endl;
cout << "max size " << sentence.max_size() << endl;
cout << "size : " << sentence.size() << endl;
cout << "capacity " << sentence.capacity() << endl;
swap(sentence[1], sentence[3]);
sentence.insert(find(sentence.begin(), sentence.end(), "?"), "always");
sentence.back() = "!";
copy(sentence.begin(), sentence.end(),
ostream_iterator<string>(cout, " "));
cout << endl;
cout << "max size " << sentence.max_size() << endl;
cout << "size : " << sentence.size() << endl;
cout << "capacity " << sentence.capacity() << endl;
return 0;
}