string vector declaration

Hi,

I'm trying to declare a vector of strings but it doesn't seem to be working.

vector<string> colourMenu ("Red", "Orange", "Yellow", "Green", "Blue", "Purple");

This should work shouldn't it?

instead I'm having to do this:
1
2
3
4
5
6
7
vector<string> colourMenu;
colourMenu.push_back("Red");
colourMenu.push_back("Orange");
colourMenu.push_back("Yellow");
colourMenu.push_back("Green");
colourMenu.push_back("Blue");
colourMenu.push_back("Purple");


Is what I'm doing already the only way of doing it?
Last edited on
You need to use a recent compiler and enable C++11 support if necessary.
Even then, the correct syntax is:
vector<string> colourMenu {"Red", "Orange", "Yellow", "Green", "Blue", "Purple"};
If you are using Code::Blocks, go to
Settings-->Compiler and debugger...
Under
Compiler Flags
check
Have g++ follow the coming C++0x ISO C++ language standard [-std=c++0x]
box. Now your first, shorter version should work.
Topic archived. No new replies allowed.