0

When I initialize a vector in C++ like this:

#include <string>
#include <vector>
using std::vector;
using std::string;
int main() {

  vector<int> v1 = {1, 2, 3, 4};
  return 0;
}

I got this error:

prog1.cpp:8:15: error: non-aggregate type 'vector<int>' cannot be initialized with an initializer list
  vector<int> v1 = {1, 2, 3, 4};
              ^    ~~~~~~~~~~~~
1 error generated.

Any idea why this happens?

zell
  • 9,830
  • 10
  • 62
  • 115

1 Answers1

5

Initializer lists were introduced from C++ 11 onwards, so you'll need to specify that (or a higher) version while compiling (-std=version) if your using an older standard for default compilation.