Overloads for iostream

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?U3RldmUgQmVobWFu?=

    Overloads for iostream

    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. " :-)
  • David Wilkinson

    #2
    Re: Overloads for iostream

    Steve Behman wrote:
    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_istr eam::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 Wilkinson
    Visual C++ MVP

    Comment

    • =?Utf-8?B?U3RldmUgQmVobWFu?=

      #3
      Re: Overloads for iostream

      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,

      "David Wilkinson" wrote:
      Steve Behman wrote:
      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_istr eam::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 Wilkinson
      Visual C++ MVP
      >

      Comment

      Working...