Hello Dear Community,
i have got a big problem. Im about to program a RPG and, of course, the player has got an inventory. The items in this inventory are stored in a linked list and have IDs in form of strings.
player.cpp: (just the most relevant)
1 2 3 4 5 6 7 8 9 10
|
#include <list>
#include <string>
using namespace std;
class CPlayer {
friend class CGame;
private:
list <string> m_inventory;
}
|
Of course, when the player saves the game, the inventory has to be saved too.
game.cpp(just the m. R.)
1 2 3 4 5 6 7 8 9 10 11 12 13
|
#include <fstream>
using namespace std;
class CGame{
private:
ofstream m_out;
ifstream m_in;
public:
void save (CPlayer* player);
void load (CPlayer* player);
}
|
Now, in my code I write the linked list into the file savegames.sav
1 2 3 4 5 6 7
|
void CGame::save(CPlayer* player){
m_out.open("savegames.sav", ios::out);
m_out.write((char* ) &player->m_inventory, sizeof(player->m_inventory));
m_out.close();
}
|
In another function i load the list:
1 2 3 4 5
|
void CGame::load(CPlayer* player){
m_in.open("savegames.sav", ios::in);
m_in.read((char* ) player->m_inventory, sizeof(player->m_inventory));
m_in.read();
}
|
And when i access the loaded linked list with the .empty() function or so,
Windows says the following:
<Mygame.exe> funktioniert nicht mehr (in English: doesnt run anymore).
I tried so much to fix that but i dint reach my aim. Please help me, cause if this evil problem was the reason for me to must stop my project, id be very sad.