Advertisement

skipping a statment

Started by November 09, 2000 07:34 PM
0 comments, last by slightlywhacked 24 years, 2 months ago
I have this section of code in my program infile.get(listing19, 50); infile.ignore(80, ''\n''); infile.close(); cin>> overwrite_number; cout << "What is the model of the truck?\n"; cin.get (truck_name, 50); cin.ignore (80, ''\n''); cout << "What is the name of the truck manufacturer?\n"; cin.get (truck_manufacturer, 50); cin.ignore (80, ''\n''); when it gets to take input for truck_name it skips it.. it reads what is the model of the truck what is the name of the manufacturer of the truck now it waits for input.. any ideas?? thanx in advance
BAHcows go moomoos go cow
I have had this problem often. My solution used to be to put a useless cin >> random; statement before the one that was getting skipped, but that is just a workaround. I recently learned that the problem is the carraige return is not being removed from the keyboard buffer by cin all the time. If you flush cin (I forget the syntax, maybe cin.flush()?) then it won''t do this anymore.

--------------------


You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming


You are unique. Just like everybody else.

Yanroy@usa.com

Visit the ROAD Programming Website for more programming help.

--------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

Yanroy@usa.com

This topic is closed to new replies.

Advertisement