Boost logo

Boost Users :

From: Rupert Swarbrick (rupert.swarbrick_at_[hidden])
Date: 2006-04-07 10:37:39


Lynn Allan wrote:
> I was wondering if the following would work "cross-platform" (It seems to
> work ok with the Microsoft Visual Studio vc7.1 compiler, but I am ignorant
> of other compilers):
>
> #void load_file(std::string& s, std::istream& is)
> #{
> # if(is.bad()) return;
> # // Use 0 as CrLf delimiter to cause entire file to be read
> # getline(is, s, '\0');
> #}
Well, there's an immediate problem if the file contains any NULL bytes,
which most non-text files do - the code will instantly stop on them.
There may be a faster way using a getline() loop, based on the fact that
many bytes are not \0, but I'm not sure that you'd actually lose much
overhead, given that the stream is likely to be buffered?

I think that the code given is probably the simplest that is actually
guaranteed to work.

Please tell me if I'm being an idiot of course!

Rupert


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net