Lesson 10 of 24

vector: The Growable Array

9 min 30 XP

The STL (Standard Template Library) is C++'s superpower. A vector is an array that grows: push_back adds, size() counts, v[i] or v.at(i) reads. Competitive programmers use vectors everywhere.

Example: edit me and press Run

Output Loading C++ (first time takes a few seconds)
Press Run to see the result here.

v.at(i) checks bounds and throws an exception; v[i] doesn't check but is faster.

Challenge

+30 XP

Read n and n numbers and print their prefix sums (each position holds the running total). Input: 5 1 2 3 4 5 Output: 1 3 6 10 15

Output Loading C++ (first time takes a few seconds)
Press Run to see the result here.