Explain the the problem for me. plzz..

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2008
Posts: 1
Reputation: zahidullah is an unknown quantity at this point 
Solved Threads: 0
zahidullah zahidullah is offline Offline
Newbie Poster

Explain the the problem for me. plzz..

 
0
  #1
Aug 21st, 2008
Below are the two lines code. Plz give a detailed explanation of these two lines

while (cin.get() != '\n')
continue;
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1463
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Explain the the problem for me. plzz..

 
0
  #2
Aug 21st, 2008
What do YOU tink they mean?
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: Explain the the problem for me. plzz..

 
0
  #3
Aug 21st, 2008
It's a WRONG attempt to eat the rest of input line on cin (for example, you get the 1st word and you want to skip other stuff).
if cin is attached to a file (not to console), you may get cin.eof condition before '\n' so you never get '\n' in these two lines of code.
Right solution (one of);
  1. while (cin && cin.get() != '\n')
  2. continue;
  3. // or simple
  4. while (cin && cin.get() != '\n')
  5. ;
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1463
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Explain the the problem for me. plzz..

 
0
  #4
Aug 21st, 2008
Originally Posted by ArkM View Post
It's a WRONG attempt to eat the rest of input line on cin (for example, you get the 1st word and you want to skip other stuff).
if cin is attached to a file (not to console), you may get cin.eof condition before '\n' so you never get '\n' in these two lines of code.
Right solution (one of);
  1. while (cin && cin.get() != '\n')
  2. continue;
  3. // or simple
  4. while (cin && cin.get() != '\n')
  5. ;
The correct solution to clearing the input stream is explained here.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 15
Reputation: findsyntax has a little shameless behaviour in the past 
Solved Threads: 2
findsyntax findsyntax is offline Offline
Newbie Poster

Re: Explain the the problem for me. plzz..

 
0
  #5
Aug 21st, 2008
Hi,
I am Rammohan from Bangalore and working as a Technical lead in big IT firm .
Solution for your answer is follows:


The Syntax of the snippet code is 100% correct.
It mean that continue your while loop until the input reaches to the next line...
If you press enter key In your input stream then the loop will come out otherwise it will contnue....

Regards,
Rammohan Alampally,
<snip false signature>
Last edited by Ancient Dragon; Aug 21st, 2008 at 7:39 am. Reason: snip false signature
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: Explain the the problem for me. plzz..

 
0
  #6
Aug 21st, 2008
I did not invent a new (incorrect) method to flush input stream.
It was a correct version of the original snippet (skip a rest of a line).
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC