An idiomatic way of reading lines from a stream:
{ std::ifstream filein("Hey.txt"); for (std::string line; std::getline(filein, line); ) { std::cout << line << std::endl; } }
Note:
No close() . C ++ takes care of resource management for you when using idiomatically.
Use the free std::getline , not the stream member function.
source share