You can in C++0x:
int* p = new int[3] { 1, 2, 3 };
...
delete[] p;
But I like vectors better:
std::vector<int> v { 1, 2, 3 };
If you don’t have a C++0x compiler, boost can help you:
#include <boost/assign/list_of.hpp>
using boost::assign::list_of;
vector<int> v = list_of(1)(2)(3);
More Related Contents:
- How to emulate C array initialization “int arr[] = { e1, e2, e3, … }” behaviour with std::array?
- How to initialize std::array elegantly if T is not default constructible?
- C++11: Correct std::array initialization?
- Now that we have std::array what uses are left for C-style arrays?
- too many initializers for ‘int [0]’ c++
- C++: Using for loop I need to take infinite values of a point using arrays. How can I take values of point [ ] until 2 points of are equal
- Invalid operands to binary expression while implementing vector [closed]
- How do I take values from text file and input into a 2D array? c++
- Why is list initialization (using curly braces) better than the alternatives?
- Initialization of all elements of an array to one default value in C++?
- Array[n] vs Array[10] – Initializing array with variable vs numeric literal
- Does “int size = 10;” yield a constant expression?
- What are the differences between C-like, constructor, and uniform initialization?
- Why can’t simple initialize (with braces) 2D std::array? [duplicate]
- What are the advantages of list initialization (using curly braces)?
- How do I initialize a member array with an initializer_list?
- Convert std::tuple to std::array C++11
- How does the range-based for work for plain arrays?
- Range-based for loop on a dynamic array?
- How to construct std::array object with initializer list? [duplicate]
- Is it possible to initialize std::vector over already allocated memory?
- what is the best modern c++ approach to construct and manipulate a 2d array [closed]
- How can I make `new[]` default-initialize the array of primitive types?
- Is int arr[ ] valid C++?
- Different ways of initializing an object in c++
- How does std::end know the end of an array?
- What’s the difference between parentheses and braces in c++ when constructing objects
- Is std::array movable?
- Interfacing C++11 array with Cython
- Initializing an std::array of non-default-constructible elements?