We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6229b98 commit 8276c44Copy full SHA for 8276c44
file_read_lines.cpp
@@ -4,6 +4,7 @@
4
#include <string>
5
6
//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
8
int main()
9
{
10
std::ifstream infile("a.txt");
@@ -16,6 +17,16 @@ int main()
16
17
std::cout << a << " " << b << std::endl;
18
}
19
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
+
30
infile.close();
31
32
//Method 2
0 commit comments