Hello,
I'm new to this board but was browsing through trying to find previous questions with the cin.get command. I am writing a program that creates reads in a student's first name (FirstName).
FirstName is defined under a data structure called StudentRecord:
// Type declarations
enum GenderType {MALE, FEMALE};
enum RegistrationType {T, M, U};
struct StudentRecord
{
char FirstName[31];
char MiddleInitial;
char LastName[31];
int StudentID;
GenderType Gender;
RegistrationType Registration;
float GPA;
};
StudentRecord Student;
FirstName is 31 characters in length to include a return character. Our instructor gave us no special condition to check for the student's name. I am stuck on how to at least ensure that the end user types only 30 characters so that the 31st will be used as the return character.
Here is my function that reads in the FirstName:
void InputFirstName(StudentRecord& aStudent) // Function heading
{
cin.ignore(31, '\n');
system("cls");
cout << "Enter Student's First Name: ";
cin.get(aStudent.FirstName, 31);
return;
}
Can somebody help?
Thanks!