Help initialising vectors

Hello there! I'm having issues initialising vectors on my system and I would love some help!

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <vector>
#include <string>

int main(){

    std::vector<std::string> vect{"Doot", "dootin", "dootalicious"};
    
    std::cout << "Hello World!" << std::endl;
    return(0);

};


It gives me the error:
1
2
3
4
5
main.cpp:7:34: error: expected ';' at end of declaration
    std::vector<std::string> vect{"Doot", "dootin", "dootalicious"};
                                 ^
                                 ;
1 error generated.


I kind of understand what the error means, it almost appears like a logic error, but I'm not sure.. When I place a semi-colon where it asks me to, it doesn't initialise with the strings.. But when I run this code on cpp.sh it works wonderfully..?
Last edited on
The constructor that accepts an initializer_list was instroduced in c++11. So your compiler is probably outdated or you need to add a compiler flag like -std=c++11.

See what happens when you set c++98 in cpp.sh.
Topic archived. No new replies allowed.