trying to clear an "enter" in the cin...

I am having an issue clearing an enter in my buffer.. When the user hits "A" to add a student the program starts asking for information.. Apparently there is a "enter" in the buffer that I cant seem to clear out. Line 51 is skipped completely.

Any Suggestions??

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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <iostream>
#include <string.h>
#include <memory.h>

using namespace std;

#include "Address.h"
#include "ARRAY.h"
#include "FixedLengthDigitString.h"
#include "FixedLengthString.h"
#include "Name.h"
#include "Phone.h"
#include "Student.h"
#include "WCS_String.h"

void main ()
{
	WCS_String						Filename ("Test.txt");
	Array <Student, 0, 25>			A1;
	Student			S1;
	WCS_String		temp;
	WCS_String		temp1;
	char			a;
	a = temp1.GetAt(a,1);
	cout << "Hello, To view the students you have saved to your file named (" << Filename << ") please press (V)." << endl << endl;
	cout << "To add students to your database please press (A)." << endl;
	cout << "*Note* Student database cannot be greater than 25." << endl << endl;
	cout << "To sort your students by ID, please press (I)" << endl;
	cout << "To sort your students by Name, please press (N)" << endl << endl;
	
	

	switch (a)

	{
		case 'V':
		case 'v':

			cout << " These are the students you currently have saved to the file: " << Filename << endl;
			A1.Read(Filename);
			A1.Display();
			cout << "*****************************************" << endl;
			break;

		case 'A':
		case 'a':

			
			cout << "Please enter the following information." << endl;
			cin.clear();
			cout << endl << "Please enter the students ID number" << endl;
			temp.ReadLine();
			S1.SetID(temp);
			cout << "Please enter the students last Name." << endl;
			temp.ReadLine();
			S1.SetLast(temp);
			cout << "Please enter the students First Name." << endl;
			temp.ReadLine();
			S1.SetFirst(temp);
			cout << "Please enter the students Middle Name." << endl;
			temp.ReadLine();
			S1.SetMiddle(temp);
			cout << "Please enter the students Street Address." << endl;
			temp.ReadLine();
			S1.SetStreet(temp);
			cout << "Please enter the students City." << endl;
			temp.ReadLine();
			S1.SetCity(temp);
			cout << "Please enter the students State." << endl;
			temp.ReadLine();
			S1.SetState(temp);
			cout << "Please enter the students Zip Code." << endl;
			temp.ReadLine();
			S1.SetZip(temp);
			cout << "Please enter the students (3) digit Area Code." << endl;
			temp.ReadLine();
			cout << "Please enter the students (7) digit Phone Number." << endl;
			temp.ReadLine();
			//A1.SetAt(A1.GetInUse(),S1);
			S1.Display();
			cout << "If you would like to write this new student to the file please press (w)" << endl;
			cin >> temp;
				if(temp == 'w' || temp == 'W')
					A1.Write(Filename);
				else
				break;
			break;

		case 'I':
		case 'i':

			A1.Read(Filename);
			cout << "These are the students you currently have saved on file sorted by ID: " << endl;
			A1.SortName();
			A1.Display();
			cout << "*****************************************" << endl;
		break;
			
		case 'N':
		case 'n':

			WCS_String						Filename ("Test.txt");	
			Array <Student, 0, 25>			A1;
			A1.Read(Filename);
			cout << "These are the students you currently have saved on file sorted by Name: " << endl;
			A1.SortID();								 
			A1.Display();

		break;
	}
	
	
	//cout << " These are the students you currently have saved to the file: " << Filename << endl;
	//A1.Read(Filename);
	//A1.Display();
	//cout << "*****************************************" << endl;
	//cout << "These are the students you currently have saved on file sorted by ID: " << endl;
	//A1.SortName();
	//A1.Display();
	//cout << "*****************************************" << endl;
	//cout << "These are the students you currently have saved on file sorted by Name: " << endl;
	//A1.SortID();								 it works
	//A1.Display();

	
	

	//A1.Write(Filename);

	// Make a switch statement to ask the user to sort by ID/Name or Read/Write to file, or Input new data.
	//to input a Student object into my array I have to, A1.SetAt(A1.GetInuse(),S1)
	//so I have to make an GetInUse.  Done!

	
	


}
Last edited on
You can use std::cin.ignore(std::numeric_limits<streamsize>::max(), '\n');

This will ignore everything up to and including the first newline (enter) encountered.
Thank you so much!
Topic archived. No new replies allowed.