0
How can we receive pointer array with cin ?
I define : char *s [5] ; int i = 0; for ( i <0 ; i++) cin >> s [i]; but it doesn't run and it has bug
1 Odpowiedź
+ 2
Your for loop has errors. You need to add the semicolon before the condition and the condition must be i<5.
=> for(;i<5;i++) cin>>s[i];
And secondly, to read a string inside a character pointer, you need to allocate memory for its characters before reading.
=> for(;i<5;i++)
{s[i]=new char[30]; cin>>s[i];}