|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: Apr 2002
Città: Vigevano(PV)
Messaggi: 2124
|
[C++]Persistenza
Codice:
/* ### 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; } Ho ragione o sbaglio??? Tnk
__________________
Gnu/Linux User ![]() Ultima modifica di Luc@s : 01-06-2004 alle 13:06. |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 01:02.