Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <cstring>
  4. #include "stdio.h"
  5. #include <conio.h>
  6.  
  7. using namespace std;
  8. class tekst {
  9. char *p;
  10. public:
  11. tekst() {
  12. p = new char[1];
  13. }
  14. void assign(char *t) {
  15. strcpy(p, t);
  16. }
  17. tekst(char *t) {
  18. p = t;
  19. }
  20. void operator=(tekst a) {
  21. strcpy(p, a.p);
  22. }
  23. void print() {
  24. cout << p << endl; //użyć printf bo cout ssie
  25. }
  26. void operator!() {
  27. cout << this->p << endl; //tu to samo
  28. }
  29.  
  30. tekst operator+(tekst &source) {
  31. char *temporary;
  32. int expectedSize = strlen(source.p) + strlen(p) + 1;
  33. temporary = new char[expectedSize];
  34. strcpy(temporary, p);
  35. strcat(temporary, source.p);
  36. p = new char[expectedSize];
  37. strcpy(p, temporary);
  38. delete[]temporary;
  39. return this->p;
  40. }
  41.  
  42. };
  43.  
  44. int main()
  45. {
  46. tekst a, b, c;
  47. b.assign("Tekscior"); //tu może wywali błąd ale podobno jest ładnie więc co sie bede kłócił
  48. b.print();
  49. a = b;
  50. !a;
  51. _getch();
  52. a.assign("Tekst");
  53. !a;
  54. a + b;
  55. !b; !a;
  56. _getch();
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement