Skip to content

Commit 8276c44

Browse files
note on EOF
1 parent 6229b98 commit 8276c44

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

file_read_lines.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <string>
55

66
//https://stackoverflow.com/questions/7868936/read-file-line-by-line-using-ifstream-in-c
7+
//https://stackoverflow.com/questions/43956124/c-while-loop-to-read-from-input-file
78
int main()
89
{
910
std::ifstream infile("a.txt");
@@ -16,6 +17,16 @@ int main()
1617
std::cout << a << " " << b << std::endl;
1718
}
1819

20+
/*
21+
note that using:
22+
while(infile){
23+
infile >> a;
24+
infile >> b;
25+
}
26+
will give you one extra line!
27+
that's because EOF will be set "after" you read to end of the file
28+
*/
29+
1930
infile.close();
2031

2132
//Method 2

0 commit comments

Comments
 (0)