Code (c++): #include <iostream> // fuer Datenhandling #include <fstream> // fuer Textfarbe usw. #include <conio2.h> // fuer Vectoren #include <vector> // Namensraum std verwenden using namespace std; /** * Klasse zum Verarbeiten von Gewicht **/ class CWeight { private: struct sWeightEntry { char chDate[10]; float fWeight; sWeightEntry(const char *date, float weight) : // Konstruktor fWeight(weight) // setzen von lokalem fWeight auf weight { memcpy(chDate, date, sizeof(chDate)); // kopieren der Array chDate[9] += '\0'; // sicherheitshalber } }; public: // oeffentliche Variablen vector<sWeightEntry> vWeightList; // oeffentliche Funktionen definieren /** * Gewicht in Klassen-Vektor schreiben * * @param char chDate Datum bestehend aus 10 Zeichen * @param float fWeight Gewicht * @return void **/ void AddWeight(const char *chDate, float fWeight) { cout << chDate << " : " << fWeight << "\n"; vWeightList.push_back(sWeightEntry(chDate, fWeight)); } }; // nav class // hier weggelassen, da es im Grunde nur Ausgabe des Menüs ist class CDragonfly { private: // private vars CWeight mWeight; // vars to stop while-loops bool bEnd; bool bEndWeight; int iInput; char chInput; // private functions /** * get an int from user and return it * @return int integer which is entered by user **/ int getIInput() { textcolor(LIGHTGREEN); int iInput; cin >> iInput; textcolor(LIGHTGRAY); return iInput; } /** * get a float from user and return it * @return float float which is entered by user **/ float getFInput() { textcolor(LIGHTGREEN); float fInput; cin >> fInput; textcolor(LIGHTGRAY); return fInput; } /** * get a char from user and return it * @return char char which is entered by user **/ char getChInput() { textcolor(LIGHTGREEN); char chInput; cin >> chInput; textcolor(LIGHTGRAY); return chInput; } int save() { ofstream output("scale.df", ios::binary); if(output == NULL) { return -1; } output.write((char *) &mWeight, sizeof(mWeight)); output.close(); return 0; } public: CDragonfly() { // open file to read ifstream fileInput("scale.df", ios::binary); if(fileInput == NULL) { //return -2; } fileInput.read((char *) &mWeight, sizeof(mWeight)); bEnd = false; while(bEnd != true) { CNav::MainNav(); iInput = getIInput(); switch(iInput) { case 1: bEndWeight = false; while(bEndWeight != true) { CNav::Weight(); chInput = getChInput(); switch(chInput) { case 'q': // go out of this menu bEndWeight = true; break; case 'o': // show the overview if(fileInput == NULL) { //return -2; } fileInput.read((char *) &mWeight, sizeof(mWeight)); for(unsigned int i = 0; i < mWeight.vWeightList.size(); i++) { cout << mWeight.vWeightList[i].chDate << "\t:\t" << mWeight.vWeightList[i].fWeight << "\n"; }; iInput = getIInput(); break; case 'n': // new weight-date input cout << "\nDatum:\n\n"; textcolor(LIGHTGREEN); char chDate[10]; cin >> chDate; textcolor(LIGHTGRAY); cout << "\nGewicht:\n\n"; float fWeight; fWeight = getFInput(); mWeight.AddWeight(chDate, fWeight); save(); break; } } break; case 98: // show the main information CNav::Info(); chInput = getChInput(); break; case 99: save(); fileInput.close(); clrscr(); bEnd = true; break; } } } }; // Hauptfunktion int main(); int main() { CDragonfly mDragonfly; return 0; } Problem tritt also an sich bei CDragonfly() am Anfang beim Auslesen der Datei auf. Edit: ach ja - und schönen Urlaub
#include <iostream> // fuer Datenhandling #include <fstream> // fuer Textfarbe usw. #include <conio2.h> // fuer Vectoren #include <vector> // Namensraum std verwenden using namespace std; /** * Klasse zum Verarbeiten von Gewicht **/ class CWeight { private: struct sWeightEntry { char chDate[10]; float fWeight; sWeightEntry(const char *date, float weight) : // Konstruktor fWeight(weight) // setzen von lokalem fWeight auf weight { memcpy(chDate, date, sizeof(chDate)); // kopieren der Array chDate[9] += '\0'; // sicherheitshalber } }; public: // oeffentliche Variablen vector<sWeightEntry> vWeightList; // oeffentliche Funktionen definieren /** * Gewicht in Klassen-Vektor schreiben * * @param char chDate Datum bestehend aus 10 Zeichen * @param float fWeight Gewicht * @return void **/ void AddWeight(const char *chDate, float fWeight) { cout << chDate << " : " << fWeight << "\n"; vWeightList.push_back(sWeightEntry(chDate, fWeight)); } }; // nav class // hier weggelassen, da es im Grunde nur Ausgabe des Menüs ist class CDragonfly { private: // private vars CWeight mWeight; // vars to stop while-loops bool bEnd; bool bEndWeight; int iInput; char chInput; // private functions /** * get an int from user and return it * @return int integer which is entered by user **/ int getIInput() { textcolor(LIGHTGREEN); int iInput; cin >> iInput; textcolor(LIGHTGRAY); return iInput; } /** * get a float from user and return it * @return float float which is entered by user **/ float getFInput() { textcolor(LIGHTGREEN); float fInput; cin >> fInput; textcolor(LIGHTGRAY); return fInput; } /** * get a char from user and return it * @return char char which is entered by user **/ char getChInput() { textcolor(LIGHTGREEN); char chInput; cin >> chInput; textcolor(LIGHTGRAY); return chInput; } int save() { ofstream output("scale.df", ios::binary); if(output == NULL) { return -1; } output.write((char *) &mWeight, sizeof(mWeight)); output.close(); return 0; } public: CDragonfly() { // open file to read ifstream fileInput("scale.df", ios::binary); if(fileInput == NULL) { //return -2; } fileInput.read((char *) &mWeight, sizeof(mWeight)); bEnd = false; while(bEnd != true) { CNav::MainNav(); iInput = getIInput(); switch(iInput) { case 1: bEndWeight = false; while(bEndWeight != true) { CNav::Weight(); chInput = getChInput(); switch(chInput) { case 'q': // go out of this menu bEndWeight = true; break; case 'o': // show the overview if(fileInput == NULL) { //return -2; } fileInput.read((char *) &mWeight, sizeof(mWeight)); for(unsigned int i = 0; i < mWeight.vWeightList.size(); i++) { cout << mWeight.vWeightList[i].chDate << "\t:\t" << mWeight.vWeightList[i].fWeight << "\n"; }; iInput = getIInput(); break; case 'n': // new weight-date input cout << "\nDatum:\n\n"; textcolor(LIGHTGREEN); char chDate[10]; cin >> chDate; textcolor(LIGHTGRAY); cout << "\nGewicht:\n\n"; float fWeight; fWeight = getFInput(); mWeight.AddWeight(chDate, fWeight); save(); break; } } break; case 98: // show the main information CNav::Info(); chInput = getChInput(); break; case 99: save(); fileInput.close(); clrscr(); bEnd = true; break; } } } }; // Hauptfunktion int main(); int main() { CDragonfly mDragonfly; return 0; }
--http://www.justsayhi.com/bb/html_quiz
Stichwortwolke anzeigen
Foren-Regeln