Overloads for iostream

  • Thread starter Thread starter Steve Behman
  • Start date Start date
S

Steve Behman

I thought that the << operator would act to get a whole line from a ifstream
but it doesn't. It

Is there an overload of << for some stream type that reads a whole text line
from a file?

I have tried the << operator within ifstream but it doesn't seem to work
with it.

PS: I am fairly sure that getline will do the job with ifstreams but it
seems so "inelegant." :-)
 
Steve said:
I thought that the << operator would act to get a whole line from a ifstream
but it doesn't. It

Is there an overload of << for some stream type that reads a whole text line
from a file?

I have tried the << operator within ifstream but it doesn't seem to work
with it.

PS: I am fairly sure that getline will do the job with ifstreams but it
seems so "inelegant." :-)

Steve:

It is >> operator that reads from streams, not << operator.

But

std::basic_istream::getline
std::getline (for std::string)

are what you want.

If you wish, you may define your own Line class (or struct) and define >>
operator for it.
 
David, thank you so much.

It has been 12 years since I last wrote a C++ program (or any other program
for that matter). And since I, perhaps unfortunately, chose the .NET paradigm
I have had so much to learn afresh let alone recall the glories of classes in
C++.

I'm sorry to be such a dunce but, thanks again anyhow.

Sincerely,
 
Back
Top