rendered paste bodyvoid save() {
ostringstream str;
str << sFirst << chr(9) << iFirstScore << chr(9) << sSecond << chr(9) << iSecondScore << chr(9) << sThird << chr(9) << iThirdScore;
ofstream fh ("scores.dat");
if (fh.is_open()) {
fh << str.str();
fh.close();
}
else {
cout << "Couldn't open file: scores.dat" << endl;
}
}
void load() {
string data;
ostringstream temp;
ifstream fh ("scores.dat");
if (fh.is_open()) {
while (!fh.eof()) {
getline(fh, data);
}
fh.close();
}
else {
cout << "Couldn't open file: scores.dat" << endl;
}
int del = 1;
int type = 0;
for (int i=0; i<data.size(); i++) {
if (data[i] == chr(9)) {
if (del == 1) {
if (type == 0) {
sFirst = temp.str();
type = 1;
}
else {
iFirstScore = atoi(temp.str().c_str());
type = 0;
del++;
}
}
if (del == 2) {
if (type == 0) {
sSecond = temp.str();
type = 1;
}
else {
iSecondScore = atoi(temp.str().c_str());
type = 0;
del++;
}
}
if (del == 3) {
if (type == 0) {
sThird = temp.str();
type = 1;
}
else {
iThirdScore = atoi(temp.str().c_str());
type = 0;
del++;
}
}
temp.str("");
}
else {
temp << data[i];
}
}
}