fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. struct mystring : public std::string
  6. {
  7. // ... appropriate constructors are an exercise left to the reader
  8. mystring& operator=(const char* right)
  9. {
  10. if (right == NULL)
  11. clear();
  12. else
  13. std::string::operator=(right);
  14. return *this;
  15. }
  16. };
  17.  
  18. int main() {
  19. mystring s1, s2;
  20. s1 = NULL;
  21. s2 = "hello";
  22. cout << "-" << s1 << "- -" << s2 << "-" << endl;
  23. return 0;
  24. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
-- -hello-