std::basic_filebuf<CharT,Traits>::is_open
來自 cppreference.com
< cpp | io | basic_filebuf
bool is_open() const; |
||
如果最近一次呼叫 open() 成功,並且此後沒有呼叫 close(),則返回 true。
目錄 |
[編輯] 引數
(無)
[編輯] 返回值
如果關聯的檔案已開啟,則為 true,否則為 false。
[編輯] 注意
此函式通常由 std::basic_fstream::is_open() 呼叫。
[編輯] 示例
執行此程式碼
#include <fstream> #include <iostream> int main() { std::ifstream fs("test.txt"); std::filebuf fb; fb.open("test.txt", std::ios_base::in); std::cout << std::boolalpha << "direct call: " << fb.is_open() << '\n' << "through streambuf: " << fs.rdbuf()->is_open() << '\n' << "through fstream: " << fs.is_open() << '\n'; }
輸出
direct call: true through streambuf: true through fstream: true
[編輯] 參閱
開啟一個檔案並將其配置為關聯字元序列 (public member function) | |
重新整理輸出緩衝區並關閉關聯檔案 (public member function) |