ifstream/ofstream writing in header file class

Hello,

Having an issue with the operators >> and << that I'm using to save/load data to a data file. The operators are being used in a class contained in a header file linked by my main program. Here's the code. I can post the compiler error if needed.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <fstream>

using namespace std;

int a, b, c;

class SaveLoadGame
{
public:
string SaveLoadData;
ifstream SaveData_f;
ofstream LoadData_f;
};

SaveLoadGame::SaveLoadGame()
{
SaveLoadData = "filestring";
}

void SaveLoadGame::Save()
{
SaveData_f.open(SaveLoadData.c_str());
SaveData_f << a << " " << b << " " << c;
SaveData_f.close();
}



The thing I find strange is that cout << and cin >> work fine in the same way...

Thanks!
An ifstream would be used to read from a file, and an ofstream to write to one. Therefore, SaveData_f should be an ofstream and LoadData_f should be an ifstream.
Ugh, I feel like an idiot. I was looking at it for like, half an hour too. Should've looked longer before posting.

Thanks for the help!
Topic archived. No new replies allowed.