-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1.7.cpp
More file actions
40 lines (37 loc) · 780 Bytes
/
1.7.cpp
File metadata and controls
40 lines (37 loc) · 780 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
33
34
35
36
37
38
39
40
#include <iostream>
#include <fstream>
//#include <algorithm>
#include <string>
using namespace std;
int main()
{
// read file
cout << " read files \n";
ifstream in_file("ifile.txt");
if (!in_file)
{ cerr << "oops! unable to open input file"; return -1; }
string name;
string gender;
int age;
while (in_file >> name)
{
cout << " the name is :" << name << endl;
in_file >> gender >> age;
cout << "the gender: " << gender << "; the ag :" << age << endl;
}
// write file
cout << "write files \n";
ofstream out_files("ofiles.txt");
if (!out_files)
{ cerr << "oops, unable to open output files"; return -1; }
int cnt = 3;
while (cnt--)
{
cout << "name";
cin >> name;
cout << "age:";
cin >> age;
out_files << name << age << endl;
}
return 0;
}