Luc@s
01-06-2004, 13:03
/*
### Copyright (c) 2004 Luca Francesca
### This script is provided under the terms of the GNU General Public License
### (see http://www.gnu.org/licenses/gpl.html for the full license text.)
*/
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class CProva
{
private:
int n;
public:
CProva(): n(0){};
CProva(int N): n(N){};
~CProva(){};
friend ostream& operator<<(ostream& os, CProva& c)
{
os << c.n;
return os;
};
friend istream& operator>>(istream& is, CProva& c)
{
is >> c.n;
return is;
};
};
int main(int argc, char *argv[])
{
CProva c(10);
ofstream of("i.txt");
ifstream ifs("i.txt");
// save the state of class
of << c << "\n";
of.close();
// sreload the state of class
ifs >> c;
cout << c << "\n";
ifs.close();
cout << endl;
char esc;
std::cin.get(esc);
return 0;
}
In questo modo ottengo una specie di persistenza dei dati.
Ho ragione o sbaglio???
Tnk
### Copyright (c) 2004 Luca Francesca
### This script is provided under the terms of the GNU General Public License
### (see http://www.gnu.org/licenses/gpl.html for the full license text.)
*/
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class CProva
{
private:
int n;
public:
CProva(): n(0){};
CProva(int N): n(N){};
~CProva(){};
friend ostream& operator<<(ostream& os, CProva& c)
{
os << c.n;
return os;
};
friend istream& operator>>(istream& is, CProva& c)
{
is >> c.n;
return is;
};
};
int main(int argc, char *argv[])
{
CProva c(10);
ofstream of("i.txt");
ifstream ifs("i.txt");
// save the state of class
of << c << "\n";
of.close();
// sreload the state of class
ifs >> c;
cout << c << "\n";
ifs.close();
cout << endl;
char esc;
std::cin.get(esc);
return 0;
}
In questo modo ottengo una specie di persistenza dei dati.
Ho ragione o sbaglio???
Tnk