1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
bool read_File(const char* fileName, std::vector <Entry> allData){
//create temp vector to add file data into before adding it to struct vect.
std::vector <std::string> temp;
int row = 0, j = 0;
char currChar;
std::string tempLine;
std::ifstream fileInput;
fileInput.open(fileName);
//make sure the file opens
//return error if it doesn't, start unpacking if it is
if (fileInput.is_open()){
//open the doc and set specifications.
//LabelParams(columnHeader,rowHeader) 0 = true, -1 = false
//SeparatorParams(delimiter, trim, hasCR, quoted line break, remove quotes from cells)
rapidcsv::Document doc(fileName, rapidcsv::LabelParams(0,-1), rapidcsv::SeparatorParams(',', false, rapidcsv::sPlatformHasCR, true, false));
//traverse file
while (fileInput >> tempLine){
temp = doc.GetRow<std::string>(j); //grab a row and store it temporarily (has to be stored due to nature of rapidcsv .GetRow)
allData.push_back(fill_allData(temp)); //puts row in vector
j++;//increase count.
}
for (int i = 0; i < allData.size(); i++){
std::cout << allData[i] << std::endl;
}
return true;
}
return false;
}
| |