我需要阅读带有工作日的日期。首先,我需要阅读日期和工作日,然后计算总工作日,例如:
total Sunday :1000
total Monday :1000
......
我总是得到值为 0。输入文件如下所示:
23/10/2005, Sunday
26/07/2016, Tuesday
10/01/1995, Tuesday
14/10/2015, Wednesday
30/09/1982, Thursday
22/09/1993, Wednesday
21/05/1972, Sunday
23/01/2017, Monday
20/05/1974, Monday
27/11/1985, Wednesday
11/07/2005, Monday
06/09/2014, Saturday
16/03/1991, Saturday
09/03/1970, Monday
17/08/2015, Monday
04/05/2010, Tuesday
14/11/2013, Thursday
13/11/2015, Friday
08/10/1995, Sunday
07/09/1986, Sunday
.....
其中有 10000 个。
string line;
string day[7] = { "Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
ifstream infile("input.txt");
ofstream validfile("valid.txt");
ofstream invalidfile("invalid.txt");
int total = 0;
int date[2], month[2], year[4];
int Sunday = 0, Monday = 0, Tuesday = 0, Wednesday = 0, Thursday = 0, Friday = 0, Saturday = 0;
char symbol = '/';
char symbol2 = ',';
while (getline(infile, line)) {
total = total++;
}
validfile << "Valid file\n" << "The total record :" << total << endl;
while (!infile.eof()) {
infile >> day[2] >> symbol >> month[2] >> symbol >> year[4] >> symbol2 >> line;
if (line.compare(day[0]) == 0) {
Sunday++;
}
else if (line.compare(day[1]) == 0) {
Monday++;
}
else if (line.compare(day[2]) == 0) {
Tuesday++;
}
else if (line.compare(day[3]) == 0) {
Wednesday++;
}
else if (line.compare(day[4]) == 0) {
Thursday++;
}
else if (line.compare(day[5]) == 0) {
Friday++;
}
else if (line.compare(day[6]) == 0) {
Saturday++;
}
}
cout << "Total Sunday :" << Sunday << endl;
cout << "Total Monday :" << Monday << endl;
cout << "Total Tuesday :" << Tuesday << endl;
cout << "Total Wednesday :" << Wednesday << endl;
cout << "Total Thursday :" << Thursday << endl;
cout << "Total Friday :" << Friday << endl;
cout << "Total Saturday :" << Saturday << endl;