Testsuites "Comparative Performance Measurement. Reading file into
string" at
http://groups.google.com/group/perfo...73f4d1a05cfbd1
http://groups.google.com/group/sourc...a9b6f91239c909
contain several algorithms including the following ones.
==================================
ifstream ifs; // input file stream
string ret_str;
### CPP-21: std::vector and std::copy
------------------------------*------------------
vector<char> v (no_of_file_bytes);
ifs.read(&v[0], no_of_file_bytes);
ostream_iterator<char> out(oss);
copy (&v[0], &v[v.size()], out);
ret_str = oss.str();
------------------------------*------------------
### CPP-23: std::vector and istream::read()
------------------------------*------------------
vector<char> v (no_of_file_bytes);
ifs.read(&v[0], no_of_file_bytes);
ret_str = (v.empty() ? string() : string (v.begin(), v.end()));
------------------------------*------------------
==================================
Eljay Love-Jensen wrote me in private message:
std::vector does not guarantee that the memory is one contiguous block.
Your particular implementation may-or-may-not provide that guarantee -- but
reliance upon that particular implementation behavior is not portable.
So, my algorithms CPP-21 and CPP-23 are not legal because the following
two line are not legal (?).
vector<char> v (no_of_file_bytes);
ifs.read(&v[0], no_of_file_bytes);
So, we can't use read() with pointers to std::vector (?).
--
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn