Guest User

Untitled

a guest
Jan 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. #ifndef _fotografie_
  2. #define _fotografie_
  3.  
  4. #include <iostream>
  5. #include <fstream>
  6. #include <cstring>
  7.  
  8. using namespace std;
  9.  
  10. void copiastringa (const char*,char*&);
  11.  
  12. class fotografie
  13. {
  14. friend istream&operator>>(istream&,fotografie&);
  15. friend ostream&operator<<(ostream&,const fotografie&);
  16. private:
  17. char*titolo;
  18. char*formato;
  19. protected:
  20. virtual istream&leggi (istream&);
  21. virtual ostream&stampa (ostream&) const;
  22. public:
  23. fotografie()
  24. {
  25. copiastringa("",this->titolo);
  26. copiastringa("",this->formato);
  27. }
  28. fotografie(const char*t,const char*f)
  29. {
  30. copiastringa(t,this->titolo);
  31. copiastringa(f,this->formato);
  32.  
  33. }
  34.  
  35. const char*get_titolo () const { return titolo;};
  36. const char*get_formato () const {return formato;};
  37. void set_titolo (const char*t) { delete [] titolo; copiastringa (t,titolo);}
  38. void set_formato (const char*f) { delete [] formato; copiastringa (f,formato);}
  39. ~fotografie() {
  40. delete [] formato; delete [] titolo;
  41. }
  42.  
  43.  
  44.  
  45.  
  46.  
  47. };
  48.  
  49. #include "fotografie.h"
  50.  
  51. void copiastringa (const char*source,char*&destination)
  52. {
  53. destination=new char[strlen(source)+1];
  54. strcpy(destination,source);
  55. };
  56.  
  57.  
  58. istream&fotografie::leggi (istream&is)
  59. {
  60.  
  61. char buffer[20];
  62. cout<<"Titolo della foto: "<<endl;
  63. is.getline(buffer,20);
  64. set_titolo(buffer);
  65. cout<<"Formato della foto: "<<endl;
  66. is.getline(buffer,20);
  67. set_formato(buffer);
  68. return is;
  69. }
  70.  
  71.  
  72. ostream&fotografie::stampa (ostream&os) const
  73. {
  74. system("cls");
  75. os<<"Titolo: "<<titolo<<endl;
  76. os<<"Formato: "<<formato<<endl;
  77. return os;
  78.  
  79. }
  80.  
  81.  
  82. istream&operator>>(istream&is,fotografie&f)
  83. {
  84. f.leggi(is);
  85. }
  86. ostream&operator<<(ostream&os,const fotografie&f)
  87. {
  88.  
  89. f.stampa(os);
  90. }
  91.  
  92. int main(int argc, char** argv) {
  93. fotografie f;
  94. cin>>f;
  95. ostream os;
  96.  
  97. file.open("merda.bin",ios::out|ios::binary);
  98. if(!file){
  99. cout<<"Error in creating file...n";
  100. return -1;
  101. }
  102.  
  103.  
  104. file.write((char*)&f,sizeof(f));
  105. file.close();
  106.  
  107. cout<<f;
Add Comment
Please, Sign In to add comment