Hi, I have a CSV file and I want to read the CSV file in .dat format. I have done the code and it managed to show data however, it only shows one data and the data is not the same as the csv file (perhaps is my varibale declare wrongly). How do I edit to read the file according to the csv file format?
My CSV data (Stat.csv) data is as such
Petrol Price Stat
Time Cost (Per Litre) No. of Litre Total Cost
10/10/2015 15:55 2.31 200 462
11/10/2015 16:00 2.21 12 26.52
12/10/2015 12:00 2.4 125 300
12/10/2015 18:00 2.85 458 1305.3
Below is my code
Code:
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
int main ()
{
ifstream inFile;
ofstream outFile;
string date;
double cost;
int no_of_litre;
double total_cost;
inFile.open("Stat.csv");
outFile.open("Stat.dat");
while(getline(inFile, date, ';') && getline(inFile, cost, ';') && getline(inFile, no_of_litre, ';') && getline(inFile, total_cost))
{
outFile << date << " " << cost << "" << no_of_litre << "" << total_cost << endl;
}
inFile.close();
outFile.close();
system ("PAUSE");
return 0;
}