-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathmain.cpp
More file actions
42 lines (33 loc) · 862 Bytes
/
main.cpp
File metadata and controls
42 lines (33 loc) · 862 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
41
42
#include <iostream>
#include <fstream>
using std::ofstream;
using std::ifstream;
using std::cout;
using std::endl;
int main(int argc, char **argv) {
cout << "Printing the command line args..." << endl;
for (int i = 0; i < argc; i++)
cout << "arg[" << i << "] = " << argv[i] << endl;
for (int i = 0; i < 10; i++) {
cout << "Hello CS Elite Coders! " << i << endl;
}
ifstream fin(argv[1]);
if (!fin) {
cout << "Cannot open file" << endl;
}
char buffer[80];
while (fin >> buffer) {
cout << buffer << endl;
}
fin.close();
ofstream fout(argv[3]);
ofstream fout2(argv[4]);
if (!fout) {
return -1;
}
fout << "Hello world from a file!" << endl;
fout2 << "some other text in this output file" << endl;
fout.close();
fout2.close();
return 0;
}