fork download
  1. #include <cstring>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. class RCharLista
  6. {
  7. private:
  8. unsigned ilosc;
  9. char **obiekt;
  10. public:
  11. operator unsigned()const { return ilosc; }
  12. const char *operator[](unsigned p)const { return obiekt[p]; }
  13. RCharLista():ilosc(0),obiekt(0) {}
  14. ~RCharLista()
  15. {
  16. for(unsigned i=0;i<ilosc;++i) delete[] obiekt[i];
  17. delete[] obiekt;
  18. }
  19. void dodaj(const char *rzecz)
  20. {
  21. char **nowy=new char *[ilosc+1];
  22. memcpy(nowy,obiekt,ilosc*sizeof(char*));
  23. unsigned rozmiar=strlen(rzecz)+1;
  24. nowy[ilosc]=new char[rozmiar];
  25. memcpy(nowy[ilosc],rzecz,rozmiar);
  26. delete[] obiekt;
  27. obiekt=nowy;
  28. ++ilosc;
  29. }
  30. RCharLista &operator<<(const char *rzecz) { dodaj(rzecz); return *this; }
  31. };
  32. inline ostream &operator<<(ostream &s,const RCharLista &R) { for(unsigned i=0;i<R;++i) s<<R[i]<<endl; return s; }
  33.  
  34. int main()
  35. {
  36. char buf1[]="umiesz tak?";
  37. char buf2[]="... niemozliwe?";
  38.  
  39. RCharLista lol;
  40.  
  41. lol.dodaj(buf1);
  42. lol.dodaj("Nie, nie umiem?");
  43. lol<<"A to juz by bylo zupelnie ..."<<buf2;
  44.  
  45. cout<<"LOL:"<<endl<<lol<<"---"<<endl;
  46. return 0;
  47. }
Success #stdin #stdout 0.02s 2816KB
stdin
Standard input is empty
stdout
LOL:
umiesz tak?
Nie, nie umiem?
A to juz by bylo zupelnie ...
... niemozliwe?
---