I'm writing a parser that gets a line from a file and separates it (by spaces) into a string vector. Unfortunately there's no way to know how long the string will be. And to figure out what the program needs to do next, it has to compare the contents of the vector with literals.
Code:
Split * cSplit = new Split(strLine);
vector<string> vstrChunks;
vstrChunks.push_back(cSplit->first());
while(!cSplit->islast())
vstrChunks.push_back(cSplit->next());
delete cSplit;
if(vstrChunks[4] == "blah") {
//The segfault is caused here only when the 4th chunk doesn't exist in memory.
}
How can I fix it so it checks if the memory exists before comparing?