![]() |
|
#1
|
|||
|
|||
Removing the pause after a cin.ignoreHello all,
Programming student just starting out, and running into an issue when using cin.clear & cin.ignore. My intent with this is to clear the buffer of extraneous characters and numbers, while still advancing on to the next cout. But it will add an extra pause in between the 2 sets of couts. If I use just the ignore (example on the ISBN entry) for some reason it does not work, it will still either not drop the text and then jump past several cout/cin's or it will crash with an invalid data type entry after infinite looping. (Hopefully this makes sense to ya'll, if not I can try and clarify.) Here is a snippet of the code: CPP / C++ / C Code:
|
|
#2
|
|||
|
|||
Re: removign the pause after a cin.ignoreOne thing I noticed is that you're calling cin.clear(). This does not clear the buffer. This clears the error flags.
Another thing that I am not sure of is whether when the user hits enter if it will get to a \n or if it gets to a \r. This might be something to play around with. For more documentation on cin (istream), you can check: http://www.cplusplus.com/reference/iostream/istream/ |
|
#3
|
|||
|
|||
Re: removign the pause after a cin.ignoreSo the cin.clear is unnecessary? When I comment out that line, and say I add a ton of numbers to the ISBN (which is declared as an int), here is the code:
CPP / C++ / C Code:
and my result looks like: What is the title of the book?sdfdsfg What is the ISBN of the book?6376537646573456347653745 What is the Author of the book? What is the number of pages in the book? It skipped right over the Author cin/cout and went on to the number of pages. My result file looks like... sdfdsfg //this is the title line 637653764657 //this is the ISBN line //this is the author line 789 //this is the number of pages line $678.00 //this is the price line If I add the cin.clear() back in I get the following What is the title of the book?james What is the ISBN of the book?5555555555555555555555555 What is the Author of the book?jamesjamejase What is the number of pages in the book?4444444444444444 To exit the record, type in -999.0 What is the value of the book? 456 james 555555555555 jamesjamejase 4.44444e+15 //I noticed I need to adjust my format here... $456.00 |
|
#4
|
|||
|
|||
Re: removign the pause after a cin.ignoreI don't know exactly. You might try to replace the clear/ignore statements with
cin.seekg (0, ios::end); This should take you to the end of the stream. I'm not sure though, so you'll have to let us know if it works. |
|
#5
|
|||
|
|||
Re: removign the pause after a cin.ignoreI think I see what you mean about the error flag now that you say that.
( I am not trying to argue, btw, just trying to understand...) I am still getting an error, but the .clear just removes the error and allows it to continue on with the bad data, clearing it out with the ignore? is that a correct way to look at it? |
|
#6
|
|||
|
|||
Re: removign the pause after a cin.ignoreAre you, by chance, using Microsoft's Visual Studio? I'm not sure about with cout/cin, but when I used to use printf/scanf with it, it would do exactly what you're talking about and I had heard that it was either the studio or the shell (command prompt interface).
|
|
#7
|
|||
|
|||
Re: removign the pause after a cin.ignoreNope, Didn't work with the cin.seekg (0, ios::end);
When I replaced the clear/ignore with it, it did not kill the extra characters int he buffer, it just put them in the other statements and continued on. It works with the clear/ignore, I just can't figure out why it ask for a second line feed to get to the next statement.... |
|
#8
|
|||
|
|||
Re: removign the pause after a cin.ignorenope, hand coding in notepad++ then using the Borland Compiler (BCC55) to compile and link...
|
|
#9
|
|||
|
|||
Re: removign the pause after a cin.ignoreWell, I wish I could be of more help. Maybe Dave or Davis will have better advice. I just don't use a command-line interface that much. I'll let you know if I think of anything else to try.
|
|
#10
|
|||
|
|||
Re: Removing the pause after a cin.ignoreOk, thanks a lot for the suggestion. Pretty new to programming so have a lot to learn. I am posting the entire cpp file as a text file in case anyone want the whole thing.
thanks again for the help and quick response... |
Recent GIDBlog
First week of IA training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| win32 CreateProcess(), STARTUPINFO not working well for 98 console | Howard_L | C Programming Language | 0 | 09-Aug-2007 23:33 |
| best way to pause program flow - cin.get? | Jbonez | CPP / C++ Forum | 6 | 23-Oct-2005 21:57 |
| CD burner wont burn!! | robertli55 | Computer Hardware Forum | 1 | 18-Jun-2004 10:53 |
| Yet another CD burner problem: Lite-On LSC-24082K | Erwin | Computer Hardware Forum | 1 | 22-May-2004 11:28 |
| want to add a pause in a game. Help | jjj93421 | CPP / C++ Forum | 1 | 11-Feb-2004 09:33 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The