Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef _fotografie_
- #define _fotografie_
- #include <iostream>
- #include <fstream>
- #include <cstring>
- using namespace std;
- void copiastringa (const char*,char*&);
- class fotografie
- {
- friend istream&operator>>(istream&,fotografie&);
- friend ostream&operator<<(ostream&,const fotografie&);
- private:
- char*titolo;
- char*formato;
- protected:
- virtual istream&leggi (istream&);
- virtual ostream&stampa (ostream&) const;
- public:
- fotografie()
- {
- copiastringa("",this->titolo);
- copiastringa("",this->formato);
- }
- fotografie(const char*t,const char*f)
- {
- copiastringa(t,this->titolo);
- copiastringa(f,this->formato);
- }
- const char*get_titolo () const { return titolo;};
- const char*get_formato () const {return formato;};
- void set_titolo (const char*t) { delete [] titolo; copiastringa (t,titolo);}
- void set_formato (const char*f) { delete [] formato; copiastringa (f,formato);}
- ~fotografie() {
- delete [] formato; delete [] titolo;
- }
- };
- #include "fotografie.h"
- void copiastringa (const char*source,char*&destination)
- {
- destination=new char[strlen(source)+1];
- strcpy(destination,source);
- };
- istream&fotografie::leggi (istream&is)
- {
- char buffer[20];
- cout<<"Titolo della foto: "<<endl;
- is.getline(buffer,20);
- set_titolo(buffer);
- cout<<"Formato della foto: "<<endl;
- is.getline(buffer,20);
- set_formato(buffer);
- return is;
- }
- ostream&fotografie::stampa (ostream&os) const
- {
- system("cls");
- os<<"Titolo: "<<titolo<<endl;
- os<<"Formato: "<<formato<<endl;
- return os;
- }
- istream&operator>>(istream&is,fotografie&f)
- {
- f.leggi(is);
- }
- ostream&operator<<(ostream&os,const fotografie&f)
- {
- f.stampa(os);
- }
- int main(int argc, char** argv) {
- fotografie f;
- cin>>f;
- ostream os;
- file.open("merda.bin",ios::out|ios::binary);
- if(!file){
- cout<<"Error in creating file...n";
- return -1;
- }
- file.write((char*)&f,sizeof(f));
- file.close();
- cout<<f;
Add Comment
Please, Sign In to add comment