-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadFile.cpp
More file actions
40 lines (33 loc) · 1006 Bytes
/
readFile.cpp
File metadata and controls
40 lines (33 loc) · 1006 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 "readFile.hpp"
string FileName;
void readFile(vector<GradeItem>& v){
//local variables to store file content
string date,description,type ,grade, maxGrade, header;
// ask the user the file name to read
cout << "Enter a file name: ";
cin >> FileName;
//open the file
ifstream file;
file.open(FileName);
if (file){
// to know if file is open
cout << "(" << FileName << ")" <<" File is opend!"<< endl;
//Iterate as long as there is data in the file
//move the file data to local variables
getline(file,header);
while (file.good()){
getline(file,date,',');
getline(file,description,',');
getline(file,type,',');
getline(file,maxGrade,',');
getline(file,grade);
// store everthing to the vector
v.push_back(GradeItem(date,description,type,stoi(maxGrade),stoi(grade)));
}
//close the file
file.close();
}
else { // if the file doesn't exsitst this will be printed
cout << "Error! The file doesn't exist!"<< endl;
}
};