Skip to content

@Rhomboid /foo.cpp
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
C++11 range based for with containers
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <list>
#include <map>
using namespace std;
int main()
{
int arr[] { 10, 20, 30 };
string str { "string" };
vector<double> vd { 1.4142, 2.7183, 3.1415 };
set<string> ss { "foo", "bar", "baz" };
list<char> lc { 'x', 'y', 'z' };
map<int,string> mis { { 100, "hundred" }, { 20, "twenty" }, { 50, "fifty" } };
for(auto &i : arr)
cout << i << endl;
for(auto &i : str)
cout << i << endl;
for(auto &i : vd)
cout << i << endl;
for(auto &i : ss)
cout << i << endl;
for(auto &i : lc)
cout << i << endl;
for(auto &i : mis)
cout << i.first << ": " << i.second << endl;
}
10
20
30
s
t
r
i
n
g
1.4142
2.7183
3.1415
bar
baz
foo
x
y
z
20: twenty
50: fifty
100: hundred
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.