fork download
  1. #include <iostream>
  2. #include<cstring>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6. class String
  7. {
  8. private:
  9. char *sptr;
  10.  
  11. public:
  12. String() : sptr(nullptr) {}
  13.  
  14. String(char str[])
  15. {
  16. sptr = new char[strlen(str) + 1];
  17. strcpy( sptr, str );
  18. }
  19.  
  20. String(const String& source)
  21. {
  22. sptr = new char[strlen(source.sptr) + 1];
  23. strcpy( sptr, source.sptr);
  24. }
  25.  
  26. ~String()
  27. {
  28. delete [] sptr;
  29. }
  30.  
  31. String& operator=( const String& other )
  32. {
  33. if(this != &other)
  34. {
  35. String tmp( other );
  36. std::swap(tmp.sptr, sptr);
  37. }
  38. return *this;
  39. }
  40. void display()
  41. {
  42.  
  43. for( char const* p = sptr; *p != '\0'; ++ p) {
  44. std::cout << *p;
  45. }
  46. cout<<endl;
  47.  
  48. }
  49.  
  50.  
  51. };
  52.  
  53. int main()
  54. {
  55. String s1;
  56. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
Standard output is empty