-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsaveFile.cpp
More file actions
47 lines (36 loc) · 1.03 KB
/
saveFile.cpp
File metadata and controls
47 lines (36 loc) · 1.03 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
#include "saveFile.hpp"
#include <iostream>
void saveFile(){
string readingFile;
cout << "Enter the name of the file you want to read: ";
cin >> readingFile;
//open file for writing
ifstream file(readingFile);
ofstream outfile;
string outputFile;
cout << "Enter the new file name to copy data of "<< readingFile << " file: ";
cin >> outputFile;
//open file for writing
outfile.open (outputFile);
//local variables
string header,date,description,type,max,grade;
//read first line of file
getline(file,header);
//write first line
outfile << header;
while (file.good()){
//This to end newline if there is more data.
outfile << endl;
//store date to local variables
getline(file, date, ',');
getline(file, description, ',');
getline(file, type, ',');
getline(file, max, ',');
getline(file, grade);
//write to output file
outfile << date << "," << description << "," << type << "," << max <<","<< grade;
}
// close both files
file.close();
outfile.close();
}