I would like to load the contents of a text file into a vector (or into any char input iterator, if that is possible). Currently my code looks like
Another approach, using rdbuf() to read the whole file to a std::stringstream first:
#include
#include
#include
#include
// for check:
#include
#include
#include
int main() {
std::ifstream file("test.cc");
std::ostringstream ss;
ss << file.rdbuf();
const std::string& s = ss.str();
std::vector vec(s.begin(), s.end());
// check:
std::copy(vec.begin(), vec.end(), std::ostream_iterator(std::cout));
}