C++ string problem

Why I cant enter any input into the train.place1.from structure? when i compile no error occur.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
struct date
{		int day;
		int month;
		int year;	
};

struct time
{		int hour;
		int minute;	
};

struct place
{		char from[20];
		char to[20];
};

struct detail
{		struct date dod;
		struct time time1;
		struct place place1;
		char cls,coach[3];
};

  void getdetail(char choice)
{
		cout<<"Please ENTER Train Detail "<<endl;
		cout<<"Departure date(day): ";
		cin>>train.dod.day;
		cout<<"Departure date(month): ";
		cin>>train.dod.month;
		cout<<"Departure date(year): ";
		cin>>train.dod.year;
		cout<<"Departure time(hour): ";
		cin>>train.time1.hour;
		cout<<"Departure time(minute): ";
		cin>>train.time1.minute;
		cout<<"From: ";
		cin.getline(train.place1.from,21);
		cout<<"To: ";
		cin.getline(train.place1.to,21);

		Sticket(choice);
		
}
Line 36 leaves a newline in the input buffer, so your getline() reads that and thinks you've entered an empty string. Try using ignore() to get rid of it.
Topic archived. No new replies allowed.