Reputation: 1
I'm getting an unexpectred error when I initialize a vector in the main. I was expecting the following output:
0 1 2
I can't see why it's not working. I also writed the same code in another pc using the same compiler, and it works.
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> vett = {0,1,2};
for (int i : vett) {
cout << i << " ";
}
return 0;
}
error: could not convert '{0, 1, 2}' from '<brace-enclosed initializer list>' to 'std::vector<int>'|
Upvotes: 0
Views: 224
Reputation: 95
You are compiling with something older than C++11, it does not support initializer list constructor.
If you are using Code::Blocks follow these steps:
Settings -> compiler -> compiler flags -> select C++11 or above
Upvotes: 0
Reputation: 7374
You need to compile with at least C++11. List initialization came with C++11.
-std=c++11
Upvotes: 2