-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram84.cpp
40 lines (33 loc) · 1.09 KB
/
Program84.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
37
38
39
40
/* PROGRAM ILLUSTRATES THE WAY TO WORK WITH MULTIPLE FILES */
#include<iostream>
#include<fstream>
int main() {
std::ofstream fout; // creating output stream object
fout.open("Country"); // connect "country" to it
fout << "India\n";
fout << "USA\n";
fout << "UK\n";
fout.close(); // disconnect "country"
fout.open("Capital"); // connect capital
fout << "Delhi\n";
fout << "Washington\n";
fout << "London\n";
fout.close(); // disconnect "capital"
// Reading the files
const int N = 80; // size of line
char line[N];
std::ifstream fin;
fin.open("country"); // create input stream for "country" file
std::cout << "Contents of country file\n";
while (fin.getline(line, N)) { // read line by line
std::cout << line << std::endl; // display it
}
fin.close();
fin.open("Capital"); // create input stream for "Capital" file
std::cout << "\nContents of Capital file\n";
while (fin.getline(line, N)) { // read line by line
std::cout << line << std::endl; // display it
}
fin.close();
return 0;
}