c++ primer 第五版 Screen类(包含Window_mgr类)

本文深入探讨C++ Primer第五版中Screen类的设计,包括其与Window_mgr类的交互,阐述如何利用这两类实现窗口管理功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <iostream>
#include <string>
#include <vector>

class Screen
{
public:
    using pos = std::string::size_type;

    friend class Window_mgr;//声明友元

    Screen() = default;
    Screen(pos ht, pos wd, char c):height(ht),width(wd),contents(ht*wd,c){}

    Screen& display(std::ostream &os)//基于const的重载
    {
        do_display(os);
        return *this;
    }
    const Screen& display(std::ostream &os) const//基于const的重载
    {
        do_display(os);
        return *this;
    }

    Screen& set(char);//设置光标处字符
    Screen& set(pos, pos, char);//设置给定位置处字符
    char get() const//返回光标处字符
    {
        return contents[cursor];
    }
    char get(pos ht, pos wd) const;//返回给定位置处字符
    Screen& move(pos r, pos c);//将光标移动到指定位置

private:
    void do_display(std::ostream &os) const {os << contents << std::endl;}

    mutable size_t access_ctr = 0;
    pos cursor = 0;//光标的位置
    pos heigh
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值