| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 610 人关注过本帖
标题:screen类的使用,
取消只看楼主 加入收藏
未未来
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:182
专家分:157
注 册:2012-11-6
结帖率:94.87%
收藏
 问题点数:0 回复次数:0 
screen类的使用,
程序代码:
#include<iostream>
#include<string>
using namespace std;
class Screen{
    public:
    typedef std::string::size_type index;
     char get()const {return contents[cursor];}
       inline    char get(index ht,index wd)const;
    index get_cursor()const;
    Screen(index hght,index wdth,const string &cntnts);
    
    Screen& move(index r,index c);
     Screen& set(char );
        
     Screen& display(ostream &os);
        private:
    std::string contents;
    index cursor;
    index height,width;
};
Screen::Screen(index hght,index wdth,const string &cntnts=" "):contents(cntnts),
cursor(0),height(hght),width(wdth){
    contents.assign(hght*wdth,' ');
    if(cntnts.size()!=0)
    contents.replace(0,cntnts.size(),cntnts);
    
}

char Screen::get(index ht,index wd)const{
    index row=ht*width;
    return contents[row+wd];
}
inline Screen::index Screen::get_cursor() const{
    return cursor;
}
Screen& Screen::set(char c){
    contents[cursor]=c;
    return *this;
}
Screen& Screen::move(index r,index x)
{
    if(r>=height||x>=width){
        cerr<<":invelid row or c"<<endl;
        throw EXIT_FAILURE;
    }
    index row=r*width;
    cursor=row+x;
    return *this;
}
Screen& Screen::display(ostream &os){
string::size_type index=0;
while(index!=contents.size()){
    os<<contents[index];
    if((index+1)%width==0){
        os<<'\n';
    }++index;
}
    return *this;
}

int main(){
    Screen myscreen(5,6,"aaaaa\naaaaa\naaaaa\naaaaa\naaaaa\n");
    myscreen.move(4,0).set('#').display(cout);

    return 0;
}



为什么(4,0)运行程序修改的是第五行的第一个,
搜索更多相关主题的帖子: index screen color 
2013-04-22 16:27
快速回复:screen类的使用,
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016207 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved