when I try to initialise a vector of int in c++, I always get the "expected ';' at end of declaration" error.
I used the original code from C++ Primer
vector<int> v{1,2,3,4,5,6,7,8,9};
and
$ g++ -o test test.cpp
I think this is a silly question to ask, but I am sure that there is a ";"... and can not manage to search an answer.. Thanks.
g++
assumes C++03 by default, and the syntax you're trying to use came in C++11. Change the compilation line to:
$ g++ -std=c++11 -o test test.cpp
Or, as I'd personally prefer:
$ g++ -Wall -Werror -pedantic -std=c++1y -o test test.cpp
:)
Note: whether you'd use c++0x
, c++11
, or c++1y
(and possibly c++14
) depends mostly on the compiler version, as those were introduced in succesion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With