I'm trying to input multiple strings into an array.
I tried using 2 dimensional array
Code:
#include<iostream.h>
int main()
{
const int ROWS=3;
const int COLS=20;
char array[ROWS][COLS];
cout<<"enter some text: "<<endl;
cin.getline (array, ROWS, '\n');
......
I know the mistake is right there at cin.getline , but I can't stuff anymore parameters into that. I know you can use a for loop for numbers, but string is different.
I tried using normal arrays
Code:
....
const int MAX=30;
char array[MAX];
char indicator ='y';
while (indicator=='y' || indicator =='Y')
{
cout<<"enter some text: "<<endl;
cin.getline(array, MAX, '\n');
cout<<"continue? (y/n)?: ";
cin>> indicator;
}
cout<<array;
...
The "while loop" doesnt work for some reason. I just get this:
Code:
output: enter some text:
intput: abc
output: continue?(y/n)?:
input: y
output: enter some text:
continue?(y/n)?
why does it loop only once??