int main() { string x=""; ifstream inFile; inFile.open("C:/WINDOWS/system32/drivers/etc/hosts"); if (!inFile) { cout << "Unable to open file"; exit(1); // terminate with error } string buffer; while (inFile >> buffer) { x+=buffer; } inFile.close(); cout << "text:" << endl << x << endl; return 0; }