C ++ Vector Initialization

#include <vector> ... //inside main function vector<int> vi3 = {42,42,42,42,42,42,42,42,42,42}; 

I am learning C ++, I thought it was possible to initialize such a vector ... Am I doing something wrong? I know about other ways to initialize a vector. The book I am reading says that this can also be done as follows:

 vector<int> vi3{42,42,42,42,42,42,42,42,42,42}; 

This is the first thing in the book that gave me an error. What am I doing wrong?

+4
source share
1 answer

It is not clear which compiler you are using, but versions of Microsoft Visual Studio until the 2013 preview do not support uniform initialization syntax {}

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

 -std=c++0x 
+10
source

Source: https://habr.com/ru/post/1490264/


All Articles