cin时遇到的问题-----不明白为什么会是这样
#include<stdlib.h>
#include<iostream>
using namespace std;
template<class T>
bool Input( T &a )
{
int cnt = 0;
while( cnt < 3 )
{
cin>> a;
if( a < 0 )
cout<< "the number less-than 0,illegal!\n";
else
return true;
++cnt;
}
return false;
};
int main()
{
int a = 0;
bool res = false;
res = Input( a );
if( res ) cout<< a;
system ( "pause" );
}
测试结果:
a
0请按任意键继续 . . .
-1
the number less-than 0,illegal!
a
the number less-than 0,illegal!
the number less-than 0,illegal!
请按任意键继续 . . .
请各位看一下,谢谢了