That's a pretty cool overall algorithm.
You're not testing for eof properly. It's best to read an entire line. And the && trick is more of a shell-scripting thing. Even so, if either of the getlines fail you still continue with the code!
And instead of using 'v' as a delimiter (which could potentially occur in a team name), you should find the string " v ".
So how about:
Code:
typedef std::string::size_type sz_t;
while (getline(inFile, line)) {
sz_t delim = line.find(" v ");
home = line.substr(0, delim);
sz_t last_space = line.find_last_of(" ");
away = line.substr(delim + 3, last_space - delim - 3);
result = line.substr(last_space + 1);
teams.insert(home);
tieResults[home + " " + away] = result;
}
This assumes perfect input. It wouldn't work with, e.g.:
Code:
Arsenal v Spurs 0-0 // extra spaces at end
// blank line
Spurs v West Ham 1-1 // spaces before " v "
Arsenal v Chelsea 2-0 // extra spaces at beginning
Chelsea v Arsenal 3-0 // spaces before result
Spurs v Arsenal 1-1 // spaces after " v "
West Ham v Chelsea 0-2 // spaces before and after " v "
Spurs v Chelsea 2-0 // spaces all over the place!
In general it's a real hastle to deal with messy input.