std::basic_fstream<CharT,Traits>::close
來自 cppreference.com
< cpp | io | basic_fstream
void close(); |
||
關閉關聯的檔案。
實際上呼叫 rdbuf()->close()。如果操作過程中發生錯誤,則呼叫 setstate(failbit)。
目錄 |
[編輯] 引數
(無)
[編輯] 返回值
(無)
[編輯] 注意
當流物件超出作用域時,此函式由 basic_fstream
的解構函式呼叫,通常不直接呼叫。
[編輯] 示例
執行此程式碼
#include <fstream> #include <iostream> #include <string> int main() { std::fstream f1("example1", std::ios::out), f2("example2", std::ios::out), f3("example3", std::ios::out); std::cout << std::boolalpha << f1.is_open() << '\n' << f2.is_open() << '\n' << f3.is_open() << '\n'; f1.close(); f2.close(); std::cout << f1.is_open() << '\n' << f2.is_open() << '\n' << f3.is_open() << '\n'; }
可能的輸出
true true true false false true
[編輯] 另請參閱
檢查流是否關聯了檔案 (public member function) | |
開啟檔案並將其與流關聯 (public member function) | |
重新整理輸出緩衝區並關閉關聯檔案 ( std::basic_filebuf<CharT,Traits> 的公共成員函式) |