#include<iostream>
using namespace std;
class screen
{
public:
typedef std::string::size_type pos;
screen() = default;
screen(pos ht, pos wd, char ch):height(ht), width(wd),
contents(ht*wd ,ch){}
screen(pos ht, pos wd) :height(ht), width(wd), contents(ht*wd, ' '
){}
screen &move(pos r, pos c)
{
pos row = r*width;
cursor = row + c;
return *this;
}
screen &set(char c)
{
contents[cursor] = c;
return *this;
}
screen &set(pos r, pos col, char ch)
{
contents[r*width + col] = ch;
return *this;
}
screen &display( )
{
cout <<contents;//右操作数没有可接受得转换
//怎么输出contents中得所有内容
}
private:
pos cursor = 0;
pos height = 0, width = 0;
string contents;
};
int main()
{
screen a(5, 5, 'x');
a.move(4,0).set('#').display();
cout << endl;
a.display();
system("pause");
return 0;
}
using namespace std;
class screen
{
public:
typedef std::string::size_type pos;
screen() = default;
screen(pos ht, pos wd, char ch):height(ht), width(wd),
contents(ht*wd ,ch){}
screen(pos ht, pos wd) :height(ht), width(wd), contents(ht*wd, ' '
){}
screen &move(pos r, pos c)
{
pos row = r*width;
cursor = row + c;
return *this;
}
screen &set(char c)
{
contents[cursor] = c;
return *this;
}
screen &set(pos r, pos col, char ch)
{
contents[r*width + col] = ch;
return *this;
}
screen &display( )
{
cout <<contents;//右操作数没有可接受得转换
//怎么输出contents中得所有内容
}
private:
pos cursor = 0;
pos height = 0, width = 0;
string contents;
};
int main()
{
screen a(5, 5, 'x');
a.move(4,0).set('#').display();
cout << endl;
a.display();
system("pause");
return 0;
}