65,211
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
using namespace std;
class Screen
{
public:
typedef string::size_type index;
Screen& move(index r,index c);
Screen& set(char m);
void display(ostream& os);
private:
string contents;
index cursor;
index height,width;
};
Screen& Screen::move(index r,index c)
{
height=r;
width=c;
cursor=height*width+c;
return *this;
}
Screen& Screen::set(char m)
{
contents[cursor]=m; //这里出错了么?
return *this;
}
void Screen::display(ostream& os)
{
os<<contents;
}
void main()
{
Screen myScreen;
myScreen.move(4,0).set('#').display(cout);
}