|
Boost Users : |
From: Lynn Allan (l_d_allan_at_[hidden])
Date: 2006-04-07 09:54:27
Thanks for providing and maintaining regex.
The following code is used in a number of the example snippets:
#void load_file(std::string& s, std::istream& is)
#{
# s.erase();
# if(is.bad()) return;
# s.reserve(is.rdbuf()->in_avail());
# char c;
# while(is.get(c))
# {
# if(s.capacity() == s.size())
# s.reserve(s.capacity() * 3);
# s.append(1, c);
# }
#}
My impression is that this code is used because some compilers won't accept
a simpler and more direct approach.
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');
#}
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