Thread: cin.get question...

  1. #1
    Registered User
    Join Date
    Jan 2002

    Question cin.get question...


    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');
    cout << "Enter Student's First Name: ";
    cin.get(aStudent.FirstName, 31);

    Can somebody help?


  2. #2
    Registered User
    Join Date
    Nov 2001
    Store firstname in a string object. If the string object's length is 30 or larger, return an error.


  3. #3
    Registered User
    Join Date
    Jan 2002

    Thumbs up Thanks kuphryn!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  2. Question...
    By TechWins in forum A Brief History of
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  3. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  4. Question about linked lists.
    By cheeisme123 in forum C++ Programming
    Replies: 6
    Last Post: 02-25-2003, 01:36 PM
  5. Question, question!
    By oskilian in forum A Brief History of
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM