Advertisement Jump to content
Sign in to follow this  

Buffer Help!

This topic is 4660 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, this is regarding some code that I'm writing for class involving classes and methods and things of that nature. Basically im supposed to be writing a Student class with all the regular members of a student and having some methods that compute GPA , read and write that data blah blah... Well ive been having some serious problems with the buffers for input. After printing the schedules and stuff it will randomly stop taking input and crash. I have tried, gets(), getline(), cin.get(), gets_s() for usage and they all work pretty much the same. Is there a way to flush the cin/cout buffer (i know about istream/ostream::flush but it seems to me that I need to fix non-file buffers). Any feedback would be appreciated. snippets below... void collegeStudent::readSchedule(void) { cout << "-=Student Schedule=-" << endl << endl; cout << numClasses << " number of classes." << endl; //debug for (int x=0;x<numClasses;x++) { cout << "Enter the class name:\n"; cin.ignore(2); //ignores 'fake' buffer input until '\n' gets_s(coursesAndGrades[x].className,30); //I usually have probllems about here... cout << "Enter number of hours this class provides:\n"; cin >> coursesAndGrades[x].hours; cout << "Enter your letter grade in this class:(A-F)\n"; cin >> coursesAndGrades[x].grade; } }

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!