Hey guys, been trying to figure this out for days now with no luck. I am creating a program that needs to read a line of an csv file into a vector of strings. Then each of these vectors are put into a vector to contain them all in the same place. I am struggling right now with getting the input into the right strings. The CSV file will look something like this:
"000","01","01","01",Continuityr1", "20/200/2000ohm (Auto-RANGE)","0.30ohm","this is a good test"
"002","01","01","01",Continuityr1", "Insulation 500V L/N", "20/200/2000Mohm (Auto-RANGE)","9.69Mohm","bla bla bla"
I will add code to get rid of the quotation marks once I can get each one individually inside the vector.
The code I have right now is basic and I have tried multiple different things. But because there is no comma on the end of the last input of the line then it adds the first of the next too the same input. So I've tried figuring out how to split them but I'm really unsure on what I'm doing, as I said this has had me stuck for a few days now!
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
|
while (std::getline(csvFile, currentLine, ','))
{
int quotationMarks = 0;
// If currentLine is abnormally large
if (currentLine.size() > 6)
{
for (int a = 0; a < currentLine.size(); a++)
{
if (currentLine[a] == '"')
{
quotationMarks++;
}
}
if (quotationMarks > 2)
{
// Get the rest of the line
std::getline(csvFile, currentLine, '\n');
// Pushback full vector onto the main vector
vectorOfInputVectors.push_back(tempVector);
tempVector.clear();
}
}
// Pushback word onto temp vector
tempVector.push_back(currentLine);
}
|
With this the output is pretty messed up...
http://imgur.com/a/pkgIg
I have set it to print each string individually and then leave a line then move onto the next vector. I have no clue where to go from here... Anyone's help would be appreciated massively.