From 10dd87e479c5a0faf63771734bf2a8d55cc215ab Mon Sep 17 00:00:00 2001 From: "Stephen M. McQuay" Date: Sat, 5 May 2012 14:05:47 -0600 Subject: [PATCH] updated loops example --- ilists.cc | 2 +- loops.cc | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/ilists.cc b/ilists.cc index 469e9b9..28ca183 100644 --- a/ilists.cc +++ b/ilists.cc @@ -12,6 +12,6 @@ thang scalar = {3.14, 42}; thang anArray[] = {{1.1, 1}, {2.2, 2}, {3.3, 3}}; int main() { - // vector v = { ??? } + // vector v = { ??? } ... see init_new return 0; } diff --git a/loops.cc b/loops.cc index c2ab19e..b3124e7 100644 --- a/loops.cc +++ b/loops.cc @@ -1,5 +1,6 @@ #include #include +#include #include using namespace std; @@ -11,11 +12,29 @@ const vector mcquays = { "derek", }; -// const vector 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 nums = { 1, 2, 3, 4, 5 }; + for(auto & n: nums) { + n--; + } + + for(auto n: nums) { + cout << n << endl; + } + + map age_for_mcquay = { + {"stephen", 31}, + {"michael", 29}, + {"bryan", 27}, + {"derek", 21}, + }; + + for(auto p: age_for_mcquay) { + cout << p.first << " " << p.second << endl; + } }