📄 8-15.cpp
字号:
#include<iostream.h>
#include<string.h>
class output
{
static char outbuf[255]; //用作资源共享的输出缓冲区
static int inuse; //当inuse为0时,缓冲区可以使用,否则不能使用
static int oindex; //数组outbuf的下标
char str[80];
int i;
int who;
public:
output(int w,char *s)
{
strcpy(str,s);
i=0;
who=w;
}
int putbuf()
{
if(!str[i])
{
inuse=0;
return 0;
}
if(! inuse)inuse=who;
if(inuse!=who)return-1;
if(str[i])
{
outbuf[oindex]=str[i];
i++;
oindex++;
outbuf[oindex]='\0';
return 1;
}
}
void show()
{
cout<<outbuf<<'\n';}
};
char output::outbuf[255];
int output::inuse=0;
int output::oindex;
main()
{
output o1(1,"This is a test"),o2(2,"of statics.");
while(o1.putbuf()|o2.putbuf());
o1.show();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -