Declaring String Array

My compiler is giving me a handful of error on just this one line. I have used this technique before without any problems so i am a little confused. Any suggestions?

string myArray[] = {"cat", "dog", "fish", "bear"};

Thanks,
Nick
Play fair; at least tell us the errors. We're not psychic.
If this array is defined as a class member it's not possible to initialize the array like that in C++03. The array has to be initialized in the constructor.
1
2
3
4
5
6
7
8
9
10
11
12
13
class A
{
public:
	A()
	{
		myArray[0] = "cat";
		myArray[1] = "dog";
		myArray[2] = "fish";
		myArray[3] = "bear";
	}
private:
	string myArray[4];
};
closed account (j2NvC542)
Project > Build options > Compiler settings > Compiler Flags > check "Have g++ follow the coming C++0x ISO C++ language standard [-std=c++0x]"

Might be this. If it is you'll get a warning about missing curly braces. You should write it like this:
1
2
3
#include <array>

array<string> myArray { {"cat", "dog", "fish", "bear"} };
thank you guys, i figured it out
Topic archived. No new replies allowed.