if (!cin) {
cin.clear();
cin.get();
}
cin.get(); //read end of line after last input
cin.get(); //wait for user to press <Enter>
首先我并不知道这啥玩意儿= =
Test_3
#include <iostream>
const int MAX = 5;
int main()
{
using namespace std;
int number[MAX];
cout << "Enter please: " << endl;
for (int i = 0; i < MAX; i++) {
cout << "The " << i << " : ";
while (!(cin >> number[i])) { //must number
cin.clear(); //reset input
while (cin.get() != '\n')
continue;
cout << "Must enter a number : ";
}
}
double sum = 0;
for (int i = 0; i < MAX; i++)
sum += number[i];
cout << "The average is : " << sum / MAX << endl;
}
对错误输入的处理
Test_4
#include <iostream>
#include <fstream>
int main()
{
using namespace std;
char name[20];
ofstream hiahia; //amzing character
hiahia.open("fuckyou.txt");
cout << "Enter your name : ";
cin.get(name, 20);
cout << fixed; //what's the meaning of fixed
cout.precision(2); //精确的
cout.setf(ios_base::showpoint);
cout << "Your name : " << name << endl;
hiahia << fixed;
hiahia.precision(2);
hiahia.setf(ios_base::showpoint);
hiahia << "Your name : " << name << endl;
hiahia.close();
return 0;
}
Test_1#include <iostream>//maybe we can use use 枚举enum{white,black,yeelow};int main(){ using namespace std; int code; cout << "Enter plaese: "; cin >> code; if (code ==...