updated loops example
This commit is contained in:
parent
57712098eb
commit
10dd87e479
@ -12,6 +12,6 @@ thang scalar = {3.14, 42};
|
||||
thang anArray[] = {{1.1, 1}, {2.2, 2}, {3.3, 3}};
|
||||
|
||||
int main() {
|
||||
// vector<thang> v = { ??? }
|
||||
// vector<thang> v = { ??? } ... see init_new
|
||||
return 0;
|
||||
}
|
||||
|
27
loops.cc
27
loops.cc
@ -1,5 +1,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
@ -11,11 +12,29 @@ const vector<string> mcquays = {
|
||||
"derek",
|
||||
};
|
||||
|
||||
// const vector<int> nums = { 1, 2, 3, 4, 5 };
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user