Strange vector definition

I was looking at some examples of vectors in my C++ textbook, and I came across this vector initialization:
 
vector<string> names {"John", "Rick", "Charlie"};

When compiling that inside a program, I got this error:
vec_test.cc:8:50: error: expected ';' after expression
        vector<string> names {"John", "Rick", "Charlie"};
                                                      ^
                                                      ;      

What I'm wondering is, is this a valid vector initialization? Because the book I found it in said that it worked. Is my compiler just messed up, or is that an invalid vector initialization?

Note: I tried modifying it with this instead:
1
2
3
4
vector<string> names;
names.push_back ("John");
names.push_back ("Rick");
names.push_back ("Charlie");

And it worked fine. So I can use that instead, but I was just wondering about that weird initialization.

My compiler is LLVM clang++ 1000.10.44.4

Thanks,
max
Last edited on
Are you braindead?
How many times do you need to be told to compile as at least C++11.
*smh* Thank you @dutch. I keep forgetting about that. Welp, I should see if I can set my compiler to default to c++20, just so it will stop doing this to me. Or so I stop doing it to myself.
Topic archived. No new replies allowed.