943,925 Members | Top Members by Rank

Ad:
  • C++ Tutorial
  • Views: 68561
  • C++ RSS
Dec 18th, 2008
0

Re: How do I flush the input stream?

Click to Expand / Collapse  Quote originally posted by Traicey ...
Why should you complicate things while there is a easy way out, I mean C++ alone is complicated
I totally agree with you, all you want to get is one line of string and see what you are supposed to do, as if it is rocket science..
Banned
serkan sendur is offline Offline
2,057 posts
since Jan 2008
Jun 20th, 2010
0

Re: "Flushing" the input stream

I love it! Would it be possible to make cin.get() save the string as well as the escape character (commonly '\n'). This way it wouldn't ever be 'nothing' because you'd always get the \n character at least. I also have much use for the \n character because its easy to remove and sometimes annoying to re-add.
Junior Poster
u8sand is offline Offline
131 posts
since Dec 2008
Jun 27th, 2010
0

Re: "Flushing" the input stream

have you tried cin.ignore();

here's an example
c++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main(){
  5. int num = 0;
  6.  
  7. //literal output
  8. cout << "enter a number";
  9. //input from keyboard(includes /n when enter is pressed)
  10. cin >> num;
  11. //variable output
  12. cout << "you entered: "<< num;
  13. //pause so output can be read
  14. cin.ignore(); //CLEAR INPUT STREAM
  15. cin.get(); //read any input
  16. }
Last edited by andersondo; Jun 27th, 2010 at 2:56 pm.
Newbie Poster
andersondo is offline Offline
1 posts
since Jun 2010
Jul 11th, 2010
-3

go low-level

Forget iostream.
cpp Syntax (Toggle Plain Text)
  1. #include <conio.h>
  2. #define IOFLUSH {while(_kbhit())_getch();}
  3. #define PAUSE {if(!_getch())_getch();}
Light Poster
wisaacs is offline Offline
46 posts
since Jun 2010
Aug 15th, 2010
-1

Re: "Flushing" the input stream

USe fflush() see it helps??
Newbie Poster
prerit is offline Offline
6 posts
since Aug 2010
Aug 23rd, 2010
0

Re: "Flushing" the input stream

>have you tried cin.ignore();
That solution is incomplete, hence the existence of this thread. Did you even bother reading it?

>Forget iostream.
>USe fflush() see it helps??

Please don't riddle my thread with bad advice. If you don't understand why your solutions are hideous, you have no business suggesting them to other people. Learn first, then teach.
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Aug 24th, 2010
0

Re: "Flushing" the input stream

I think this thread has enough "advice" replied to the original post. Time for a lock.
Last edited by Nick Evan; Aug 24th, 2010 at 6:01 am.
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006
Message:
Previous Thread in C++ Forum Timeline: redefine equlity of pairs
Next Thread in C++ Forum Timeline: Check it out again guys





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC