Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String& operator+=(const String& s) {
- for (size_t i = 0; i < s.sz; ++i) {
- push_back(s[i]);
- }
- return *this;
- }
- String& operator+=(const char c) {
- push_back(c);
- return *this;
- }
- String& operator+=(const char& add_chr) {
- push_back(add_chr);
- return *this;
- }
- String substr(size_t start, size_t count) const {
- String res(count, '\0');
- for (size_t i = start; i < start + count; ++i) {
- res[i - start] = str[i];
- }
- return res;
- }
- //это вне функции
- String operator+(const char lstr, const String& rstr) {
- String copy(1, lstr);
- copy += rstr;
- return copy;
- }
- String operator+(const String& lstr, const char rstr) {
- String copy = lstr;
- copy.push_back(rstr);
- return copy;
- }
- String operator+(const String& lstr, const String& rstr) {
- String copy = lstr;
- copy += rstr;
- return copy;
- }
- bool operator==(const String& lhs, const String& rhs) {
- if (lhs.length() != rhs.length()) {
- return false;
- }
- for (size_t i = 0; i < lhs.length(); ++i) {
- if (lhs[i] != rhs[i]){
- return false;
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement