How do I check for end-of-file using the std::getline
function? If I use eof()
it won't signal eof
until I attempt to read beyond end-of-file.
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- How to replace file-access references for a module
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
The canonical reading loop in C++ is:
Just read and then check that the read operation succeeded:
Since the failure may be due to a number of causes, you can use the
eof
member function to see it what happened was actually EOF:getline
returns the stream so you can write more compactly: