Wednesday, December 12, 2012

Read text file into std::string

Taken (unmodified) from a StackOverflow reply, but I use this frequently and always have to search for it.


std::ifstream in("file.txt");
std::string contents((std::istreambuf_iterator<char>(in)), 
    std::istreambuf_iterator<char>());


No comments:

Post a Comment