-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.cpp
More file actions
71 lines (53 loc) · 1.71 KB
/
Main.cpp
File metadata and controls
71 lines (53 loc) · 1.71 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <bits/stdc++.h>
using namespace std;
//Default File Folder names
const string INPUT_FOLDER = "inputs";
const string OUTPUT_FOLDER = "edited_inputs";
const string INPUT_FILE_PREFIX = "input";
const string OUTPUT_FILE_PREFIX = "input";
/*
* this is where you will write code to edit your file
* the example shows the way to read 3 integers and print them in seperate line
*/
void editInput(ifstream &infile, ofstream &outfile)
{
//EXAMPLE STARTS
//simply take input
int a,b,c;
infile>>a>>b>>c;
//print them as you like
outfile<<a<<endl;
outfile<<b<<endl;
outfile<<c<<endl;
//EXAMPLE ENDS
}
/*
* This function generates the file name from file number
*/
string getFileName(string folder_name, string file_prefix, int file_no)
{
string s=to_string(file_no);
if(file_no >= 0 and file_no <= 9) s = "0" + s;
return folder_name + "/" + file_prefix + s + ".txt";
}
int main()
{
//Don't edit unless you know what you are doing
for(int file_no=0; ;file_no++){
string in = getFileName(INPUT_FOLDER, INPUT_FILE_PREFIX, file_no);
string out = getFileName(OUTPUT_FOLDER, OUTPUT_FILE_PREFIX, file_no);
ifstream infile;
ofstream outfile;
infile.open(in, ios_base::out | ios_base::in);
if(!infile.is_open()) break; //There is no more file to process
outfile.open(out);
if(!outfile.is_open()) {
cout<<"Output directory doesn't exist, please create the directory"<<endl;
break;
}
cerr<<"EDITING: "<<in<<" WRITING to: "<<out<<endl;
editInput(infile, outfile);
infile.close();
outfile.close();
}
}