-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfileRead.cpp
More file actions
32 lines (26 loc) · 933 Bytes
/
fileRead.cpp
File metadata and controls
32 lines (26 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
// char letter;
string line;
int i;
ifstream read("poem.txt"); //opens the file poem.txt
if (!read) { //if the file is not created
cout << "Error opening file for input" << endl;
return -1;
}
else {
for (i=0; ! read.eof(); i++) { //loops through the file until the end of the file is reached using the eof() function
//read.get(letter); //gets the next character from the file
getline(read, line); //gets the next line from the file
//cout << letter; //prints the character
cout << line << endl; //prints the line
}
}
read.close(); //closes the file
cout << "Iterations: " << i << endl; //prints the number of iterations
return 0;
}
//166 iterations=not very effiecient, thus use string instead of char