Initializing string array in C++03

What's the best way to initialize a string array?

1
2
3
4
5
6
7
8
9
10
11
// suppose I want to initialize s with "One","Two" and "Three".
// what's the best way (minimum coding) to do it in C++03?
class eggs{
private:
    string s[];

};

eggs::eggs() {
  // what am I supposed to do here? or perhaps in the declaration.. 
}


Thanks for your help. Happy coding.
Assuming s will be of a fixed size
1
2
3
4
5
6
7
8
9
10
11
12
class eggs{
private:
    string s[3];

};

eggs::eggs()
{
  s[0] = "One";
  s[1] = "Two";
  s[2] = "Three";
}


If you want to hold a variable number of strings it's a little different
if I were to declare s outside the class, I could've done it as..

 
string s[] = {"one","two","three"};


I am looking something similar to it. Remember? less coding.
As far as I know, there is no way to initialize it on one line without, say, the C++11 initializer_list or something.
If you're thinking of doing
1
2
eggs::eggs() : s{"one", "two", "three"}
{}

it is a feature of C++11. The array size must still be known at compile time to do it
Last edited on
Topic archived. No new replies allowed.