积极答复者
c++刷新不了缓冲区

问题
-
#include <iostream>
#include <iomanip>
using namespace std;
const char *ptr_dec[]={"●"};
int main()
{
M:system("title The Tank Fighting");system("mode con cols=95 lines=45");
system("color 4D");
int sentry=14;
for(int Enter_val=0;Enter_val!=sentry;Enter_val++)
{
cout<<endl;}
cout<<setw(37)<<" "<<"please the mode of game"<<endl<<endl;
cout<<setw(37)<<" "<<*ptr_dec<<" "<<"1.one man to play"<<endl<<endl;
cout<<setw(37)<<" "<<" "<<"2.two men to play "<<endl<<endl;
/*M:*/int Select_mode;
fflush(stdin);
cin>>Select_mode;
if(Select_mode==1||Select_mode==2){
if(Select_mode==1)
{
fflush(stdin); //The opeater use refurbish Buffer.cout<<"please input anything to Select checkpoints"<<endl;
int ch;
ch=getchar();
system("cls");
}else
{system("cls");
int sentry=14;
for(int Enter_val=0;Enter_val!=sentry;Enter_val++)
{
cout<<endl;}
cout<<setw(37)<<" "<<"please the mode of game"<<endl<<endl;cout<<setw(37)<<" "<<"1.one man to play"<<endl<<endl;
cout<<setw(37)<<" "<<*ptr_dec<<" "<<"2.two men to play "<<endl<<endl;
cout<<""<<endl;
fflush(stdin);
int ch;
ch=getchar();
system("cls");
}}
else
{
fflush(stdin);
cout<<"you opeator is inlegal ,please input one or two"<<endl;//就是这句
goto M;
}当我输入不是1和2时,就会无限输出cout的语句我明明刷新的缓冲区怎么没用
return 0;
}
答案
-
我试了试您的代码,没有无限输出这句啊~ cout<<"you opeator is inlegal ,please input one or two"<<endl;
Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.
- 已标记为答案 Elegentin XieModerator 2013年2月5日 11:33
全部回复
-
我试了试您的代码,没有无限输出这句啊~ cout<<"you opeator is inlegal ,please input one or two"<<endl;
Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.
- 已标记为答案 Elegentin XieModerator 2013年2月5日 11:33