Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: non-aggregate type 'vector<int>' cannot be initialized with an initializer list

Tags:

c++

vector

I am a beginner in c++ and every time I run vector<int> nums = {2, 5, 3, 7, 1}; it gives me the Error: non-arregrate type vector cannot be initialized with initializer list.

Can you tell me why?

Thanks,

like image 341
Ian Avatar asked Aug 18 '16 16:08

Ian


2 Answers

Use g++ -std=c++11 <filename> when compiling.

like image 99
Dhruv Sehgal Avatar answered Nov 12 '22 18:11

Dhruv Sehgal


Using Druhv Sehgal's answer above, this worked for me on mac

If command not found: gcc++ try

clang++ -std=c++11 <filename>

like image 25
Mote Zart Avatar answered Nov 12 '22 18:11

Mote Zart