Hello all -- I'm pretty new to C++ and C and can't figure out how to reliably detect and work around the mystery input that seems to get trapped in cin. Without any discernible pattern, VC++ seems to find something in the input buffer and thus skips the next input statement (it happens with >>, get() and getline()).
I've tried the various get() and getline() buffer-flushing code snippets, but the program stops and waits for input. I need a way to check the input buffer without the program stopping and waiting for the input. I've tried get(), getline(), peek() and various combinations of them and haven't had any luck.Code:system("cls"); cout<<" ADD EQUIPMENT\n" <<"\n\n For non-applicable items, enter 0 or N\n"; cout<<"\n Enter Name: "; getline(cin, response); strcpy(newRecord.chrName, response.c_str()); cout<<"\n Enter Weight Capacity (if applicable): "; cin>>newRecord.iCapacity;
The method works the first time, but the second time the getline() is skipped, as if there were input.
Any help would be greatly appreciated. Thanks for all the great hints I've already gotten here!