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