#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
c++ primer 第五版 Screen类(包含Window_mgr类)
最新推荐文章于 2022-05-13 23:08:32 发布