C语言中 clearerr(stdin) 是什么意思啊 ?? clearerr 要 怎么用 啊??

来源:百度知道 编辑:UC知道 时间:2024/05/26 05:42:13
C语言中 clearerr(stdin) 是什么意思啊 ?? clearerr 要 怎么用 啊??

#include <iostream>
#include <limits>
#include <cstdio>

using namespace std;

int main()
{
int i_test, c;

printf("Please enter an integer: ");
scanf("%d", &i_test);
printf("You just entered %d.\nPress enter to continue...", i_test);
while ( (c = getchar()) != '\n' && c != EOF ) ; // 清空输入流
clearerr(stdin); // 清除流的错误标记
getchar(); // 等待用户输入回车

cout << "Please enter an integer: ";
cin >> i_test;
cout << "You just entered " << i_test << ".\nPress enter to continue...";
cin.clear(); // 清除流的错误标记
cin.ignore( numeric_limits<streamsize>::max(), '\n' ); // 清空输入