10.2总结

cpp 复制代码
#include <iostream>

using namespace std;

class MyString
{
private:
    string pos1;
    string pos2;
public:
    MyString()
    {}
    MyString(string pos1,string pos2):pos1(pos1),pos2(pos2)
    {
        cout << "调用了有参构造" << endl;
    }
    MyString(const MyString &other):pos1(other.pos1),pos2(other.pos2)
    {
        cout << "调用了拷贝构造函数" << endl;
    }
    const MyString operator+(const MyString &R)const
    {
        MyString t;
        t.pos1 = pos1+R.pos1;
        t.pos2 = pos2+R.pos2;
        return  t;
    }

    const MyString operator>(const MyString &R)const
    {
        MyString t;
        t.pos1 = (pos1>R.pos1)?"true":"false";
        t.pos2 = (pos2>R.pos2)?"true":"false";
        return  t;
    }
    const MyString operator<(const MyString &R)const
    {
        MyString t;
        t.pos1 = (pos1<R.pos1)?"true":"false";
        t.pos2 = (pos2<R.pos2)?"true":"false";
        return  t;
    }
    const MyString operator==(const MyString &R)const
    {
        MyString t;
        t.pos1 = (pos1==R.pos1)?"true":"false";
        t.pos2 = (pos2==R.pos2)?"true":"false";
        return  t;
    }
    void input()
    {
        cout << "请输入pos1: ";
        cin >> pos1;
        cout << "请输入pos2: ";
        cin >> pos2;
    }


    void output() const
    {
        cout << "pos1: " << pos1 << ", pos2: " << pos2;
    }


    void show()
    {
        cout << "pos1的长度为" << pos1.size() << endl;
        cout << "pos2的长度为" << pos2.size() << endl;
        cout << "pos1= " << pos1 << " " << "pos2= " << pos2 << endl;

    }

};

int main()
{
    //    MyString s1("z","x");
    //    MyString s2("b","a");
    MyString s1;
    s1.input();
    // s1.output();
    MyString s2;
    s2.input();
    //s2.output();
    MyString s =s1+s2;
    MyString s3 =s1>s2;
    s.show();
    s3.show();
    return 0;
}

相关推荐
@小码农3 分钟前
2026年3月Scratch图形化编程等级考试一级真题试卷
开发语言·数据结构·c++·算法
这儿有一堆花4 分钟前
住宅代理(Residential Proxy)技术指南
开发语言·数据库·php
一只大袋鼠15 分钟前
Java进阶:CGLIB动态代理解析
java·开发语言
秦ぅ时17 分钟前
保姆级教程|OpenAI tts-1-hd模型调用全流程(Python+curl+懒人用法)
开发语言·python
Joseph Cooper20 分钟前
Linux HID 子系统实战:从虚拟键盘到 input 事件上报
linux·c语言·计算机外设
Eiceblue25 分钟前
使用 C# 将 Excel 转换为 Markdown 表格(含批量转换示例)
开发语言·c#·excel
爱滑雪的码农30 分钟前
Java基础十三:Java中的继承、重写(Override)与重载(Overload)详解
java·开发语言
Java面试题总结31 分钟前
使用 Python 设置 Excel 数据验证
开发语言·python·excel
【 】42334 分钟前
C++&STL(Standard Template Library,标准模板库)
java·开发语言·c++
eastyuxiao40 分钟前
OpenClaw 自动处理核心逻辑
开发语言·人工智能