Pseudocode:
Code:
Pair<int, int> parseLine(String& line)
{
auto semicolon = line.find(';');
if(semicolon == -1)
throw Exception("Unexpected format!");
int a, b;
StringBuilder sb;
line.replace(semicolon, 1, 1, ' ');
sb << line;
sb >> a;
sb >> b;
return make_pair(a, b);
}
void readFile(Array<Pair<int, int>>& myArray)
{
File file("MyAwesomeFile.BBQ");
if(file.is_open() == false)
throw Exception("Can not open MyAwesomeFile.BBQ!");
String line;
while(file.eof() == false)
{
readLine(file, line);
if(line.empty() == true)
continue;
myArray.push_back( parseLine(line) );
}
}
Das Ganze nun mit std::ifstream, std::string, std:: pair, std::vector, std::getline, std::stringstream und std::exception.
Da kommt Grundschuhlfeeling auf! Was ergibt 5+5? Bitte Wähle! 8, 9, 10, 11
Nicht direkt Spoonfeeding, aber doch recht nah dran! :p