Not sure why I get thise errors:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
error: expected primary-expression before '{' token
error: expected `;' before '{' token
[code]
 #include<iostream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

int main()
{
    vector<int> vecList;
 ostream_iterator<int> screen(cout, " ");
vecList = {12, 16, 8, 23, 40, 6, 18, 9, 75};
copy(vecList.begin() + 2, vecList.end(), screen);
cout << endl;
}
 
That code builds fine. You must be trying to build some other code: http://cpp.sh/4iay2
If it builds OKAY!!! Now why am I getting this error:
1
2
C:\Dev-Cpp\Chapter4\exercise13.cpp:11:9: error: no match for 'operator=' (operand types are 'std::vector<int>' and '<brace-enclosed initializer list>')

It really frustrates me!!!!
It seems you’re using old C++ syntax.
Try to tell the compiler you want to use new C++ features, i.e. add a proper flag to the compilation instructions.
For example, for GCC the flag would be -std=c++11 or -std=c++14 or higher.
Example:
g++ main.cpp -std=c++17 -o main.exe

Topic archived. No new replies allowed.