C++ Vectors initialization

c++, initialization, vector

Solution

It's not clear which compiler you are using, but versions of Microsoft's Visual Studio before the 2013 preview do not support the uniform initialisation syntax `{}`

If you are using gcc you need to tell it to use C++11:

-std=c++0x

Problem

``` #include <vector> ... //inside main function vector<int> vi3 = {42,42,42,42,42,42,42,42,42,42}; ``` I'm learning C++, I thought it was possible to initialize a vector like this... Am I doing something wrong? I know about the other ways of initializing a vector. In the book I'm reading it says it can also be done like this: ``` vector<int> vi3{42,42,42,42,42,42,42,42,42,42}; ``` It's the first thing on the book that gave me an error. What am I doing wrong?

Original source