std::basic_ios<CharT,Traits>::clear
提供: cppreference.com
<tbody>
</tbody>
void clear( std::ios_base::iostate state = std::ios_base::goodbit ); |
||
state の値を代入することによってストリームのエラー状態フラグをセットします。 デフォルトでは、すべてのエラー状態フラグをクリアする効果を持つ std::ios_base::goodbit を代入します。
rdbuf() がヌルポインタ (すなわち紐付けられているストリームバッファがない) の場合は、 state | badbit が代入されます。 例外を投げるかもしれません。
引数
| state | - | 設定する新しいエラー状態フラグ。 以下の定数を組み合わせることができます。
|
戻り値
(なし)
例外
| This section is incomplete Reason: link to basic_ios::exceptions, too |
例
予期しない入力の後で failbit をクリアするために引数なしの clear() を使用することができます。
Run this code
#include <iostream>
#include <string>
int main()
{
double n;
while( std::cout << "Please, enter a number\n"
&& ! (std::cin >> n) )
{
std::cin.clear();
std::string line;
std::getline(std::cin, line);
std::cout << "I am sorry, but '" << line << "' is not a number\n";
}
std::cout << "Thank you for entering the number " << n << '\n';
}
関連項目
| 状態フラグを設定します (パブリックメンバ関数) | |
| 状態フラグを返します (パブリックメンバ関数) |