I have written the following piece of code and after staring at it for the longest time and trying out a set of different things, I have accomplished nothing. The problem is that the text that is printed on the screen, although "correct", does not include the const strings I'm printing every time like "date: "
or "task: "
.
Here is the code:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int main() {
ifstream myFile("calend.txt");
vector<string> info;
string str;
while (getline(myFile, str, '-')) {
info.push_back(str);
if (info.size() > 1) {
cout << "date: " << info.at(0) << endl;
cout << "task: " << info.at(1) << endl;
info.clear();
}
}
myFile.close();
system("pause");
return 0;
}
Here is the text file (calend.txt
):
15/05-checkpoint IART
18/05-checkpoint COMP
22/05-SDIS
25/05-apresentacao PPIN
27/05-IART
28/05-apresentacao LPOO
28/05-teste PPIN
01/06-LBAW
05/06-COMP
08*14/06-PPIN
And finally here is the output:
date: 15/05
task: checkpoint IART
18/05
date: checkpoint COMP
22/05
task: SDIS
25/05
date: apresentacao PPIN
27/05
task: IART
28/05
date: apresentacao LPOO
28/05
task: teste PPIN
01/06
date: LBAW
05/06
task: COMP
08*14/06
As you can see, the first two lines are printed correctly, but afterwards it skips the const strings. Thanks in advance.