Vector Empty Check in C++
Level 293 keystrokes
Checks with empty() whether the vector v has no elements; v was just declared and is empty, so Empty is printed.
C++ code
// Declares a vector of ints with no elements1vector<int> v;// empty() returns true when size() is 02if (v.empty()) { // v is empty, so Empty is printed3 cout << "Empty" << endl;// Runs only if v has at least one element4} else { // Would print the number of elements; skipped here5 cout << v.size() << endl;6}Output
Empty
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.
<× 9;× 3(× 3)× 3.× 2"× 2{× 2}× 2>× 1