Advertisement
KShah

Untitled

Nov 12th, 2021
604
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. String& operator+=(const String& s) {
  2.     for (size_t i = 0; i < s.sz; ++i) {
  3.         push_back(s[i]);
  4.     }
  5.     return *this;
  6. }
  7.  
  8. String& operator+=(const char c) {
  9.     push_back(c);
  10.     return *this;
  11. }
  12.  
  13. String& operator+=(const char& add_chr) {
  14.     push_back(add_chr);
  15.     return *this;
  16. }
  17.  
  18. String substr(size_t start, size_t count) const {
  19.     String res(count, '\0');
  20.     for (size_t i = start; i < start + count; ++i) {
  21.         res[i - start] = str[i];
  22.     }
  23.     return res;
  24. }
  25.  
  26. //это вне функции
  27. String operator+(const char lstr, const String& rstr) {
  28.     String copy(1, lstr);
  29.     copy += rstr;
  30.     return copy;
  31. }
  32.  
  33. String operator+(const String& lstr, const char rstr) {
  34.     String copy = lstr;
  35.     copy.push_back(rstr);
  36.     return copy;
  37. }
  38.  
  39. String operator+(const String& lstr, const String& rstr) {
  40.     String copy = lstr;
  41.     copy += rstr;
  42.     return copy;
  43. }
  44.  
  45. bool operator==(const String& lhs, const String& rhs) {
  46.     if (lhs.length() != rhs.length()) {
  47.         return false;
  48.     }
  49.     for (size_t i = 0; i < lhs.length(); ++i) {
  50.         if (lhs[i] != rhs[i]){
  51.             return false;
  52.         }
  53.     }
  54.     return true;
  55. }
  56.  
  57.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement