Hi,
I can't get cin.getline to work properly, I'm using it inside a for loop.. it gets the input sucessfuly when the loop is executed for the first time(i=0), but it doesn't wait to take any input on the next times..the program just moves to the next line..
#include <iostream.h>
struct test {
char str[300];
int num;
}t[3];
int main()
{
for(int i=0; i<3; i++)
{
cout <<"-Enter Name No.:" <<i+1 <<endl;
cin.getline(t[i].str , 200);
cout <<"-Number: ";
cin >>t[i].num;
}
for(i=0; i<3; i++)
{
cout <<t[i].str <<endl;
}
return 0;
}
here is a sample execution:
-Enter Name No.:1
Jack
-ID: 45
-Enter Name No.:2
-ID:
As you see, it didn't wait to take input the second time, it moved to the next line..
one more thing, when I don't use cin inputs after getline (in the same loop, it works just fine !
any help would be appreciated :)
Thanks