updated loops example

This commit is contained in:
Stephen M. McQuay 2012-05-05 14:05:47 -06:00
parent 57712098eb
commit 10dd87e479
2 changed files with 24 additions and 5 deletions

View File

@ -12,6 +12,6 @@ thang scalar = {3.14, 42};
thang anArray[] = {{1.1, 1}, {2.2, 2}, {3.3, 3}}; thang anArray[] = {{1.1, 1}, {2.2, 2}, {3.3, 3}};
int main() { int main() {
// vector<thang> v = { ??? } // vector<thang> v = { ??? } ... see init_new
return 0; return 0;
} }

View File

@ -1,5 +1,6 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <map>
#include <iostream> #include <iostream>
using namespace std; using namespace std;
@ -11,11 +12,29 @@ const vector<string> mcquays = {
"derek", "derek",
}; };
// const vector<int> nums = { 1, 2, 3, 4, 5 };
int main() { int main() {
// iterate over mcquay boys for(auto name: mcquays) {
cout << name << endl;
// iterate over nums }
// correct numbers
vector<int> nums = { 1, 2, 3, 4, 5 };
for(auto & n: nums) {
n--;
}
for(auto n: nums) {
cout << n << endl;
}
map<string, int> age_for_mcquay = {
{"stephen", 31},
{"michael", 29},
{"bryan", 27},
{"derek", 21},
};
for(auto p: age_for_mcquay) {
cout << p.first << " " << p.second << endl;
}
} }