← C++ from Scratch Lesson 52 of 62 · 5 XP

Warm-up: how many numbers warm-up

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

std::vector is an array that grows by itself. push_back adds an element to the end, and size() tells how many there are:

std::vector<int> v;
int x;
while (std::cin >> x) {   // read until the input ends
    v.push_back(x);
}
std::cout << v.size() << '\n';

Task. Read all the numbers until the end of input into a vector and print how many there are.

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.