Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   while loop question (http://www.programmingforums.org/showthread.php?t=9074)

sackarias Mar 27th, 2006 5:25 PM

while loop question
 
:

while ( src >> word){ //code };

In this case, does (src >> word) actually do my overload for >>? Or does it just check if it's possible, then enter the loop?

I hope that makes sense...!!

Thanks!

bgeraghty Mar 27th, 2006 5:37 PM

while loops don't check if things are possible, they evaluate whether or not they are true.

sackarias Mar 27th, 2006 5:51 PM

That's what I meant by if it's possible. The way I said it was ambiguous.

Navid Mar 27th, 2006 6:29 PM

Yes, it will perform the operations in the brackets.

sackarias Mar 27th, 2006 6:36 PM

Thanks.

DaWei Mar 27th, 2006 6:39 PM

Yes? :confused: Depends on what the insertion operator (which the OP says is overloaded) has been written to return. That's not an item of information given in the post.

Navid Mar 27th, 2006 6:45 PM

It performs what ever it’s instructed to in the brackets. Whether it continues into the braces depends on the return value as DaWei said. Unless I’m wrong again.

sackarias Mar 27th, 2006 7:15 PM

ifstream& operator>>(ifstream& fin, const WordData &curWordData);

Returns fin.

DaWei Mar 27th, 2006 8:07 PM

The insertion operator typically returns the stream (a reference). Even if insertion fails, the return will not be zero unless the function is specifically written to do that. Failures are tested with other methods (e.g., good (), eof (), fail (), etc.).

PPoA Mar 27th, 2006 8:16 PM

I think he was asking if the code as written actually does the overloading. Answer to that is, no. You have to write it into a function how you want it overloaded.


All times are GMT -5. The time now is 5:13 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC