Straight to the point, I have a task -> program asks for a price input, then, in the given csv file, it compares the input price to the csv file price (last value of the line). Then the program should print out the lines in which the price is the same as input or LOWER. Note, that the csv file is as it is, some lines are "broken" if you can say so, not even. So far I removed the unnecessary spacings in lines and only perform the code if line is not empty. I had an idea to write the values of each line (values are separated by comma) to a vector and then compare to price with specific vector index, but didn't manage to get it running as it should. Please help.
fstream file("db.csv", ios::in);
float price;
string line;
cin >> price;
if (file.is_open()) {
cout << "result:" << endl;
while (getline(file, line)) {
if (!line.empty()) {
line.erase(remove(line.begin(), line.end(), ' '), line.end());
}
}
}
Here is the db.csv file data as it is (with all the whitespaces and empty lines).
Riga,Kraslava,Pr,15:00,11.00
Riga ,Kraslava,Pr ,18:00,11.00
Kraslava,Riga,Pr,08:00,11.00
Kraslava,Daugavpils,Ot ,10:00, 3.00
Ventsplis,8.00,Liepaja,Sv,20:00
Dagda,Sv
Rezekne,Riga,Tr,13:00,10.50
Dagda,Kraslava, Ce,18:00, 2.50
Dagda,Kraslava,Ce,18:00,2.50,Sv
Riga,Ventspils, Pt,09:00 , 6.70
Liepaja,Ventspils,Pt,17:00,5.50