read a string

Mar 27, 2013 at 6:47pm
char name[10]; To read a string from keyboard.
what should i use :
this : cin>>name[10];

or this : cin>>*name;
Mar 27, 2013 at 6:48pm
Try cin >> name ;

name[10] is out of the bounds of the array, and *name is the first element (only) of the array.
Mar 27, 2013 at 7:27pm
aaaaah :)
that's right
thanks
Mar 27, 2013 at 7:39pm
I recommend cin >> setw(10) >> name;, otherwise you risk buffer overflow. (or just use strings)
Topic archived. No new replies allowed.