Vector push_back in C++
Level 3119 keystrokes
Starts with an empty vector, appends 10, 20 and 30 with push_back, then prints them in the order they were added.
C++ code
// Creates an empty vector of int (size 0)1vector<int> nums;// push_back appends an element at the end; the vector grows automatically2nums.push_back(10);3nums.push_back(20);4nums.push_back(30);// Visits the elements in insertion order: 10, 20, 305for (int n : nums) { // Prints each value on its own line6 cout << n << endl;7}Output
10 20 30
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<× 5(× 4)× 4_× 3.× 3:× 1{× 1}× 1>× 1