Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <cstring>
- using namespace std;
- class String {
- private:
- char* st;
- public:
- String(int);
- String(const char* s, int);
- void dislpay()const;
- void get();
- void operator=(String);
- String operator+(String) const;
- String operator+=(String);
- bool operator==(String);
- bool operator!=(String);
- String& operator[](int);
- String operator()(int, int);
- };
- String::String(int sz = 80) {
- st = new char[sz];
- st[0] = '\0';
- }
- String::String(const char* s, int sz = 80) {
- st = new char[sz];
- strcpy(st, s);
- }
- void String::dislpay()const {
- cout << "String: " << st << endl;
- }
- void String::get() {
- cout << "Напишите строку: ";
- cin >> st;
- }
- bool String::operator==(String s) {
- if (!strcmp(st, s.st))
- return true;
- else return false;
- }
- bool String::operator!=(String s)
- {
- if(!strcmp(st, s.st))
- return false;
- return true;
- }
- void String::operator=(String s) {
- this->st = s.st;
- }
- String String::operator+(String s) const
- {
- String temp;
- strcat(temp.st = this->st, s.st);
- return temp;
- }
- String String::operator+=(String s)
- {
- return String(strcat(st, s.st));
- }
- int main() {
- setlocale(LC_ALL, "Russian");
- String st1 = "World!";
- String st2 = "Hello, ";
- st1.dislpay();
- st2.dislpay();
- String st3;
- st3 = st2 + st1;
- st3.dislpay();
- /*int a = 1, b = 2;
- if (a == b)
- cout << "lox";
- else cout << "ne lox";
- if (st1 == st2)
- cout << "Одинаковые" << endl;
- else cout << "Разные" << endl;*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement