Advertisement
eng-mg

1lineprint

Dec 2nd, 2015
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <string>
  4.  
  5. class mystring :public std::string
  6. {
  7.     public:
  8.     mystring(): std::string()
  9.         {}
  10.     mystring(const char* str): std::string(str)
  11.         {}
  12.     mystring operator *(int n)
  13.     {
  14.         mystring ret;
  15.         for (int i = 0; i < n; ++i) {
  16.             ret.append(data());
  17.         }
  18.         return ret;
  19.     }
  20.     mystring operator =(char* s)
  21.     {
  22.         return mystring(s);
  23.     }
  24.     void print_n_times(int n)
  25.     {
  26.         std::cout<< *this * 3;
  27.     }
  28. };
  29.  
  30. int main()
  31. {
  32.     mystring("Hello world \n").print_n_times(3);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement