blob: c84d8c08604c534eebf51b589866b24f448dbaf6 (
plain)
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
33
34
|
// Learning C++
// Exercise 06_01
// Opening a text file for reading, by Eduardo Corpeño
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
ifstream inFile;
string str;
int number;
char letter;
int main(){
inFile.open("people.txt");
if (inFile.fail())
cout << endl << "File not found!" << endl;
else{
while (!inFile.eof()){
getline(inFile, str);
cout << str << ", ";
getline(inFile,str);
number = stoi(str);
cout << number << ", ";
getline(inFile, str);
letter = str[0];
cout << letter << endl;
}
inFile.close();
}
return (0);
}
|