50 lines
1.3 KiB
C++
50 lines
1.3 KiB
C++
#include <iostream>
|
|
#include <fstream>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <utility>
|
|
#include <sstream>
|
|
|
|
std::vector<std::pair<std::string, std::string> > readFile(const std::string &filename) {
|
|
std::vector<std::pair<std::string, std::string> > instructions;
|
|
std::ifstream file(filename);
|
|
if(!file.is_open()) {
|
|
std::cerr << "Fehler: Datei " << filename << " konnte nicht geöffnet werden.\n";
|
|
return instructions;
|
|
}
|
|
|
|
std::string line;
|
|
while (std::getline(file, line)) {
|
|
// Entferne führende oder trailing Whitespace
|
|
if (line.empty()) continue;
|
|
|
|
std::istringstream iss(line);
|
|
std::string command;
|
|
std::string param;
|
|
|
|
if (!(iss >> command)) {
|
|
// Keine gültige Eingabe in dieser Zeile
|
|
continue;
|
|
}
|
|
|
|
// Optionalen Parameter einlesen, falls vorhanden
|
|
if (!(iss >> param)) {
|
|
// Kein Parameter vorhanden
|
|
param = "";
|
|
}
|
|
|
|
instructions.push_back(std::make_pair(command, param));
|
|
}
|
|
|
|
return instructions;
|
|
}
|
|
|
|
// Beispiel zur Nutzung
|
|
int main() {
|
|
auto result = readFile("init");
|
|
for (const auto &inst : result) {
|
|
std::cout << "Befehl: " << inst.first << " | Parameter: " << inst.second << "\n";
|
|
}
|
|
|
|
return 0;
|
|
}
|