cin.get question...

This is a discussion on cin.get question... within the C++ Programming forums, part of the General Programming Boards category; Hello, I'm new to this board but was browsing through trying to find previous questions with the cin.get command. I ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    14

    Question cin.get question...

    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!

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

    Kuphryn

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    14

    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 Cprogramming.com
    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, 08:22 PM
  4. Question about linked lists.
    By cheeisme123 in forum C++ Programming
    Replies: 6
    Last Post: 02-25-2003, 12:36 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21