?? input.cpp
字號:
#include <iostream.h>
template<class T>
bool Input(T& x)
{// Input a nonnegative value.
int NumOfAttempts = 3;
// try at most NumOfAttempts times
for (int i = 0; i < NumOfAttempts; i++) {
cout << "Enter a nonnegative value" << endl;
cin >> x;
if (x >= 0) return true;
cout << x << " is not nonnegative" << endl;
}
// did not get nonnegative value
cout << "Sorry, you get only "
<< NumOfAttempts << " chances."
<< endl;
return false;
}
void main()
{// Test Input.
int a;
if (Input(a)) cout << "The number is " << a << endl;
else cout << "Did not get a nonnegative number" << endl;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -