I was trying to run some code I wrote back in my sophomore year of college for an on campus job. The code worked back then but it will not now due to the error in the question title. Basically the code is looping through a csv file with records of volunteer hours completed. The error occurs at the try part of the try block even begins (I inserted the try block after reading various similar questions and trying to see what the actual cause of the error is). Before I added the try block, it occurred at start = end + delimiter.length();. I know that some of the coding isn't in a preferred manner, but I wrote it early in college and I haven't worked in C++ since and would appreciate any help.
else
{
auto start = 0U;
auto end = line.find(delimiter);
numberCount = 0;
while (numberCount <= timeLoc)
{
currentInfo = line.substr(start, end - start);
if (numberCount == fNameLoc)
{
rows[0][rowCount] = currentInfo;
}
if (numberCount == lNameLoc)
{
rows[1][rowCount] = currentInfo;
}
if (numberCount == IDLoc)
{
rows[2][rowCount] = currentInfo;
}
if (numberCount == timeLoc)
{
rows[3][rowCount] = currentInfo;
}
try
{
start = end + delimiter.length();
end = line.find(delimiter, start);
numberCount++;
}
catch (const std::exception& e)
{
cout << e.what() << '\n';
}
}
rowCount++;
}
Basically each if statement pulls the data from the column that was previously found based on the title of the header. Delimiter is whatever the character delimiter in the csv file is.
User contributions licensed under CC BY-SA 3.0