Inventory Program

My program is an inventory program. It compiles and runs, but when I try and enter the name of the first piece of inventory, it doesn't work. But you can fill out the rest of the information about this inventory and the next pieces following this one.
Last edited on
After you enter 2, it reads it and then leaves the newline in the buffer, so getline gets an empty string as the name.
Okay, but how do I fix that??
Quick fix: add cin.ignore(); or cin.get(); after line 26.
This will read/discard one character from the input buffer (which will hopefully be the '\n' newline character).

A better solution: add cin.ignore(numeric_limits<streamsize>::max(), '\n'); after line 26. (Requires #include <limits> )
This discards as many characters as possible from the input buffer until it reaches (and discards) a newline character.
(So if you enter "2 Hello" when it asks how many entries you want, it'll read the 2 and correctly discard the " Hello\n".)
THANK YOU!!! It works perfectly now!!
Topic archived. No new replies allowed.