#include #include #include #include int main( ) { if (std::ifstream infile("sample.txt")) { // construct string from iterator range std::string fileData(std::istreambuf_iterator(infile), std::istreambuf_iterator()); cout << "File has " << fileData.size() << "chars\n"; // don't need to manually close the ifstream; it will release the file when it goes out of scope return 0; } else { std::cout << "file not found!\n"; return 1; } }