character sequences using array

1
2
3
4
5
6
7
8
9
10
int main ()

{
            char nom[];
            string name;
            cout<<"entrer votre nom \n";
            getline(cin,name);
            nom[] = name;
  getch();
}

it gives me "storage size of 'nom' isn't known
where is the problem ??
What it says - you didn't give an array size. Just remove lines 4 and 8.
If you need the string as a C string, use the c_str() member function:
http://www.cplusplus.com/reference/string/string/c_str/
As Athar said, most of the time you don't need C type strings. If you are just playing around with this to learn how arrays work, when you define an array

char nom[];

you need to give a size for the array. Arrays have fixed length and are allocated memory at their declaration. Something like this would work though

char nom[] = "asfd";

as you are implicitly specifying the array to have length 5 (one character for the null character '\0').

But for all intents and purposes you shouldn't really need to use C strings.
Topic archived. No new replies allowed.