Syntax

C++ Create a Vector Syntax

In C++, create a vector: creates a resizable array — std::vector<int> v = {1, 2, 3}; v.push_back(4);

Quick Answer

Syntax
std::vector<int> v = {1, 2, 3}; v.push_back(4);
C++Syntax

Create a Vector

Code example
std::vector<int> v = {1, 2, 3}; v.push_back(4);

Creates a resizable array.

Learn More

How to create a vector in C++

  1. Open your C++ file or editor.
  2. Copy the example, then replace its sample names and values for your code.

C++ Create a Vector Syntax

Use std::vector<int> v = {1, 2, 3}; v.push_back(4);.

Related Syntax References

Frequently asked questions

What is the C++ syntax for create a vector?

Use this pattern: std::vector<int> v = {1, 2, 3}; v.push_back(4);

Can I copy this C++ code example?

Yes. Use Copy code and adapt the example to your program.

Is this C++ syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify