Using different forms of the cin function.

Can we not use "cin>>" immediately after "cin.get(str,max,char)"? I cant seem to accept a string from a user first, and then after that accept a char value. whenever the compiler is supposed to get the char value it exits the program. maybe I shouldnt declare the string variable and the char variable in the same line? Thanks in advance.

 
  
I guess that you leave a '\n' in the input buffer so the get() operations is giving you an empty string.
Last edited on
Let me show you an example here. This is a snippet from a code Im working on right now.
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
45
46
47
Loop:
cout<<"\nPress A to add Notes, X to exit\t";
	cin>>response;
	if(response=='X'||response=='x')
	exit(1);
	if(response=='A'||response=='a')
	cout<<"Enter the preferred date:\t";
	cin>>date;
	cout<<"Please write your appointment here and enter '*' when you are done:\t\n";
	if(date==1)
	cin.get(N1,30,'*');
	else if(date==2)
	cin.get(N2,30,'*');
	else if(date==3)
	cin.get(N3,30,'*');
	else if(date==4)
	cin.get(N4,30,'*');
	else if(date==5)
	cin.get(N5,30,'*');
	else if(date==6)
	cin.get(N6,30,'*');
	else if(date==7)
	cin.get(N7,30,'*');
	else if(date==8)
	cin.get(N8,30,'*');
	else if(date==9)
	cin.get(N9,30,'*');
	else if(date==10)
	cin.get(N10,30,'*');
	else if(date==11)
	cin.get(N11,30,'*');
	else if(date==12)
	cin.get(N12,30,'*');
	else if(date==13)
	cin.get(N13,30,'*');
	else if(date==14)
	cin.get(N14,30,'*');
	else if(date==15)
	cin.get(N15,30,'*');
	cout<<"Would you like to return to main menu?";
	cin>>R;
	if(R=='y'||R=='Y')
	goto Loop;
	else{
         cout<<"Goodbye"
}
	

in the above code, cin>>R doesnt work at all. It has no errors but the compiler just skips it and then either proceeds to the goto command or displays Goodbye. What do you think is the problem?
http://www.cplusplus.com/reference/istream/istream/get/
The delimiting character is not extracted from the input sequence if found, and remains there as the next character to be extracted from the stream


Also, learn arrays
Topic archived. No new replies allowed.