Start here · Essential guide
How to Initialize a Vector in C++
A practical guide to initializing a std::vector in C++: empty vectors, brace lists, set sizes with fill values, copies from ranges, and common mistakes.
Strings, Containers and Memory
Ways to create and fill a std::vector, and how size and resize work.
Start here · Essential guide
A practical guide to initializing a std::vector in C++: empty vectors, brace lists, set sizes with fill values, copies from ranges, and common mistakes.
Not always. Global and static ints start at 0 in C and C++, but local ints can hold an unknown value. Learn how to tell them apart and set zero on purpose.
Learn how to resize a std::vector in C++ with resize(), reserve() and clear(), including what new elements hold and when capacity actually changes.
size() returns how many elements a std::vector holds right now. Learn what it counts, how it differs from capacity and sizeof, and how to avoid common bugs.
Related topics