65,208
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int c;
char buf[ 32 ];
setbuf( stdout, buf );
while (( c=getchar()) != EOF )
putchar(c);
// cin.get();
return 0;
}



#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int c;
char buf[BUFSIZ];
setbuf(stdout, buf);
while (( c=getchar()) != EOF )
putchar(c);
fflush(stdout);
return 0;
}
[/quote]
嗯,可以。能说下原因吗,还有之前有错的原因~
不清除缓冲的话,输出为什么会错误。
还有,有cin.get()的程序是不是先把缓冲清除了在接收一个字符,所以效果就跟用了fflush一样。
谢谢了
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int c;
char buf[BUFSIZ];
setbuf(stdout, buf);
while (( c=getchar()) != EOF )
putchar(c);
fflush(stdout);
return 0;
}