-
Notifications
You must be signed in to change notification settings - Fork 2
/
stlVector.cpp
43 lines (32 loc) · 929 Bytes
/
stlVector.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
42
/*
* Basic STL vector example
*
* @author J. Alvarez
*/
#include <iostream>
#include <vector>
int main(int argc, char const *argv[])
{
std::vector<std::string> people;
people.push_back("lola");
people.push_back("lalo");
people.push_back("lelo");
people.push_back("lala");
people.push_back("lolo");
std::cout << "Normal for:" << std::endl;
for (int i = 0; i < people.size(); i++)
std::cout << (i+1) << " - " << people[i] << std::endl;
std::cout << std::endl;
std::cout << "Iterator for" << std::endl;
for (std::vector<std::string>::iterator it = people.begin();
it != people.end(); it++)
std::cout << * it << std::endl;
std::cout << std::endl;
std::cout << "And backwards:" << std::endl;
for (std::vector<std::string>::iterator it = people.end();
it != people.begin(); it--) {
std::vector<std::string>::iterator current = it - 1;
std::cout << * current << std::endl;
}
return 0;
}