Lynn Allan wrote:
#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?
Granted, the proposed code only works with non-binary data that doesn't have embedded NULL bytes. That seems a reasonable assumption for the snippets provided, as well as most situations where boost::regex would be used. And o/s buffering/caching may make it a moot point.