-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathnew1.cpp
49 lines (38 loc) · 949 Bytes
/
new1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Illustration of range-for loop
// using CPP code
#include <iostream>
#include <vector>
#include <map>
//Driver
int main()
{
// Iterating over whole array
std::vector<int> v = {0, 1, 2, 3, 4, 5};
for (auto i : v)
std::cout << i << ' ';
std::cout << '\n';
// the initializer may be a braced-init-list
for (int n : {0, 1, 2, 3, 4, 5})
std::cout << n << ' ';
std::cout << '\n';
// Iterating over array
int a[] = {0, 1, 2, 3, 4, 5};
for (int n : a)
std::cout << n << ' ';
std::cout << '\n';
// Just running a loop for every array
// element
for (int n : a)
std::cout << "In loop" << ' ';
std::cout << '\n';
// Printing string characters
std::string str = "Geeks";
for (char c : str)
std::cout << c << ' ';
std::cout << '\n';
// Printing keys and values of a map
std::map <int, int> MAP({{1, 1}, {2, 2}, {3, 3}});
for (auto i : MAP)
std::cout << '{' << i.first << ", "
<< i.second << "}\n";
}