#include <vector>
#include <iostream>
#include <string>
Go to the source code of this file.
◆ main()
Definition at line 20 of file cp9.2vector.cpp.
20 {
21 vector<string> items;
23 items.push_back("eggs");
24 items.push_back("milk");
25 items.push_back("sugar");
26 items.push_back("chocolate");
27 items.push_back("flour");
29 items.pop_back();
31 items.push_back("coffee");
33 for (unsigned int i = 0; i < items.size(); i++) {
34 if (items[i] == "sugar") {
35 items[i] = "honey";
36 }
37 }
39 vector<string>::iterator it;
40
41 for (it = items.begin(); it != items.end(); it++) {
42 if (*it == "milk") {
43 items.erase(it);
44 break;
45 }
46 }
48 return 0;
49}
void print(vector< string > v)
References print().
◆ print()
void print |
( |
vector< string > | v | ) |
|
Definition at line 6 of file cp9.2vector.cpp.
6 {
7
8
9 vector<string>::iterator vitr;
10 cout << "Items: ";
11 for (vitr = v.begin(); vitr != v.end(); vitr++) {
12 cout << *vitr;
13 if (vitr != v.end() - 1) {
14 cout << ", ";
15 }
16 }
17 cout << endl;
18}
Referenced by main().