名稱空間
變體
操作

std::basic_ios<CharT,Traits>::setstate

來自 cppreference.com
< cpp‎ | io‎ | basic ios
 
 
 
 
void setstate( iostate state );

除了當前已設定的標誌外,還設定流錯誤標誌 state。本質上呼叫 clear(rdstate() | state)。可能會丟擲異常。

目錄

[編輯] 引數

state - 要設定的流錯誤狀態標誌。它可以是以下常量的組合
常量 解釋
goodbit 無錯誤
badbit 不可恢復的流錯誤
failbit 輸入/輸出操作失敗(格式化或提取錯誤)
eofbit 關聯的輸入序列已到達檔案末尾

[編輯] 返回值

(無)

[編輯] 示例

#include <iostream>
#include <sstream>
 
int main()
{
    std::ostringstream stream;
 
    if (!stream.fail())
        std::cout << "stream is not fail\n";
 
    stream.setstate(std::ios_base::failbit);
 
    if (stream.fail())
        std::cout << "now stream is fail\n";
 
    if (!stream.good())
        std::cout << "and stream is not good\n";
}

輸出

stream is not fail
now stream is fail
and stream is not good

[編輯] 另請參閱

返回狀態標誌
(public member function) [編輯]
修改狀態標誌
(public member function) [編輯]