Ian Ian - 1 year ago 150
C++ Question

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

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?


Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download