-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.cpp
36 lines (30 loc) · 888 Bytes
/
file.cpp
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
35
36
// file.cpp, Maggie Johnson
// Description: An illustration of file processing
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
void enter_data(){
}
int main() {
string line;
char first_name[30], last_name[30]; int age;
char file_name[20];
// Collect the data.
cout << "Enter First Name: "; cin >> first_name;
cout << "Enter Last Name: "; cin >> last_name;
cout << "Enter Age: "; cin >> age;
cout << endl << "Enter the name of the file: "; cin >> file_name;
// Create an ofstream called People, open the stream for output.
ofstream People(file_name, ios::out);
// Write the output to the stream.
People << first_name << endl << last_name << endl << age << endl;
ifstream print_people(file_name, ios::in);
if (print_people.is_open()){
while(getline(print_people,line)){
cout << line << endl;
}
print_people.close();
}
return 0;
}