Auto with Vector in C++
Level 266 keystrokes
Loops over the vector {1, 2, 3} with a range-based for loop whose variable type is deduced by auto, and prints 1, 2 and 3.
C++ code
// Creates a vector with the values 1, 2 and 31vector<int> v = {1, 2, 3};// auto deduces n as int from the element type of v// n receives a copy of each element in turn2for (auto n : v) { // Prints each element on its own line3 cout << n << endl;4}Output
1 2 3
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this C++ code and how often they appear.
<× 5,× 2;× 2{× 2}× 2:× 1(× 1)× 1=× 1>× 1