Re: Winsock and IOStreams

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Eugene Gershnik (gershnik_at_hotmail.com)
Date: 09/03/04


Date: Fri, 3 Sep 2004 01:58:38 -0700

yerl@twenty.net wrote:
> No doubt this will sound n(oo|ew)bish but here goes.
>
> First,
> There are two methods of snagging a 'line' from a stream.

There are many things called stream and many ways to read from them. If you
need an advice about C++ iostreams a better place to ask is
comp.lang.c++.moderated or one of the vc newsgroups.

One small advice. If (as the title of your post suggests) you try to use
iostreams to read from a socket then I would strongly recommend to avoid
doing so. Read network data into a memory buffer and then if you wish attach
a C++ streambuf to it.

The rest is an attempt to answer your questions.

> One is the
> std function "getline" and the other is the "getline" method of the
> stream itself. Silly the stream only takes a char_type buffer when the
> 'std::getline()' takes a bonafide string reference! I prefer the one
> that takes the basic_string ref. Here's the dilema with this
> approach, I don't know how to test for EOF. :(

Check for failbit on the stream.

> Second,
> This is the silliest thing. Since we are dealing with Windows or at
> least I am I'd like to know a C++/Win programmer accepted way of
> removing the trailing '\r' from the result of one of the getline
> formats. I don't want to assume the '\r' is there so I'd appreciate
> some options.

Make sure your stream is in "text" rather than "binary" mode. In text mode
the '\r' will disappear.

> I'm still working through "Standard C++ IOStreams and Locales" so
> perhaps the answer is there.

Perhaps. In absence of any other references this is automatically the best
book on the topic.

--
Eugene


Relevant Pages

  • Re: Object Expected error
    ... Thank you very much, Marina, for your advice. ... Now, I wish to retrieve user's response and, depending on the ... don't use Response.Write to stream the script out at the ... >> I wish to call doDialog() from different places in the code behind page, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Did I miss a show???
    ... you can stream the whole thing off of CBS's own website. ... for the advice! ... "So, I'm sitting there hearing HAL say, "I'm sorry Dave, I'm afraid I ...
    (alt.tv.survivor)
  • stream
    ... I need some advice on the following: ... I'm capturing data from a stream. ... had a prior exposure to BASIC: as potential programmers they are mentally ...
    (microsoft.public.windowsmedia.sdk)
  • How to use filestream, memoryStream ,byte array and streamreader properly
    ... What is the difference among filestream, memoryStream and byte stream, ... appreciate for any advice,please help ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: "endl and " "
    ... > statement is that IOStreams have bad performance. ... you cannot point at an emergent property from the, uh, design. ... to make anything fast, for example, if there are no inherent limits such ... > concatenation of strings does not really require any form of stream. ...
    (comp.lang.cpp)