文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>第8节 类的应用举例——行编辑程序

第8节 类的应用举例——行编辑程序

时间:2010-09-01  来源:chinazhangjie

代码
/* 主题: 行编辑(使用栈)
* 作者: chinazhangjie(邮箱:[email protected])
* 开发语言: C++
* 开发环境: Microsoft Visual Studio 2008
* 日期: 2010.09.01
* 备注:该类设计的不好
*/     
#include
"stack.h" // for stack<T>

class line_edit {
public:
line_edit() { }
line_edit(
const line_edit& rle) {
elem
= rle.elem;
}
// 重载赋值运算符
line_edit& operator = (const line_edit& rle) {
if (this == &rle)
return *this;
elem
= rle.elem;
return *this;
}
// 清空
void clear() {
elem.clear();
}
// 读入(行编辑)
void read() {
elem.clear();
__line_edit();
}
// 重载 "<<"
friend
ostream
& operator << (ostream& out,line_edit& rle) {
out << rle.elem ;
return out;
}
private:
// 行编辑
void __line_edit() {
char ch ;
ch
= getchar();
while (ch != EOF) {
switch(ch) {
case '#':
if (elem.size() != 0)
elem.pop();
break;
case '@':
elem.clear();
break;
default:
elem.push(ch);
break;
}
ch
= getchar();
}
}
private:
stack
<char> elem;
};

 

相关阅读 更多 +
排行榜 更多 +
方块枪战战场安卓版

方块枪战战场安卓版

飞行射击 下载
战斗火力射击安卓版

战斗火力射击安卓版

飞行射击 下载
空中防御战安卓版

空中防御战安卓版

飞行射击 下载