Created
April 23, 2015 13:57
-
-
Save sevanspowell/782a9b569f0cd43a17c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CSV contents is a 2D array, each line has it's own row and each row is made up of the fields found in that line. | |
Vector< Vector<std::string> > csvContents; | |
std::ifstream infile(fileName.c_str()); | |
// Load elements of CSV into Vector. | |
while(infile.good()) | |
{ | |
std::string line; | |
std::getline(infile, line); | |
std::stringstream lineStream(line); | |
Vector<std::string> lineFields; | |
while (lineStream.good()) | |
{ | |
std::string subStr; | |
// Remove initial whitespaces | |
while (lineStream.peek() == ' ') | |
{ | |
lineStream.get(); | |
} | |
std::getline(lineStream, subStr, ','); | |
lineFields.append(subStr); | |
} | |
csvContents.append(lineFields); | |
} | |
// For each line, read contents | |
for (unsigned long int i = 0; i < csvContents.size(); ++i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment