I have to parse several csv files with the same basic structure and I have to save the values in different matrixes.
I'd like to save each table in a single matrix but the problem is that I have some issues with the endline character.
I tried to use the getline
function but I can't terminate the while cycle when the table is parsed.
I use this code:
// MMDS.cpp : definisce il punto di ingresso dell'applicazione console.
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
using namespace std;
int i = 0, j = 0 , z=0;
int main()
{
ifstream file("I_30_2_02_02_1.csv"); // declare file stream
string value;
string intvalue;
string check;
int jobs;
int machines;
int resources;
vector<string> JobTime;
vector<string> MachineId;
vector<string> ProcTime; //archiviato come JobId MachineId ProcTime
//prime tre righe
getline(file, value, ';'); // #jobs
getline(file, intvalue, '\n');
jobs = stoi(intvalue);
cout << "Jobs: " <<jobs << "\n";
getline(file, value, ';'); //#machines
getline(file, intvalue, '\n');
machines = stoi(intvalue);
cout << "Machines: " << machines << "\n";
getline(file, value, ';'); //#resources
getline(file, intvalue, '\n');
resources = stoi(intvalue);
cout << "Resources: " << resources << "\n";
//scritte inutili
getline(file, value, ';');
cout << value << " ";
getline(file, value, ';');
cout << value << " ";
getline(file, value, '\n');
cout << value << "\n";
//primo ciclo
while (getline(file, intvalue)) {
getline(file, intvalue, ';');
JobTime.push_back(intvalue);
getline(file, intvalue, ';');
MachineId.push_back(intvalue);
getline(file, intvalue, '\n');
ProcTime.push_back(intvalue);
//getline(file, intvalue, '\n');
}
for (i = 0; i <= ProcTime.size(); i++)
cout << JobTime[i] << " " << MachineId[i] << " " << ProcTime[i] <<endl;
cin >> intvalue;
return 0;
}
The csv file is :
#Jobs;30
#Machines;2
#Resources;4
JobId;MachineId;PrTime
1;1;12
2;0;97
3;1;54
4;1;83
5;1;56
6;0;5
7;0;18
8;1;17
9;0;15
10;0;83
JobId;DueDate;RelDate;TardPenalty
1;575;4;1
2;563;70;2
3;483;1;8
4;519;68;1
5;540;64;10
6;546;126;8
7;550;2;6
Each table is separated by the others with one blank line. Can someone help me to read each table? Thanks a lot