共用方式為


basic_fstream 類別

描述物件控制項目的插入和擷取並輸入物件使用 basic_filebuf<類別Elem, Tr>資料流緩衝區,以 Elem型別元素,類別取決於性格特性 Tr。

template <class Elem, class Tr = char_traits<Elem> >
    class basic_fstream : public basic_iostream<Elem, Tr>

參數

  • Elem
    檔案緩衝區的基本項目。

  • Tr
    檔案緩衝區 (通常是 char_traits<Elem>) 中的基礎項目的特性。

備註

物件儲存類別 basic_filebuf<Elem, Tr>物件。

注意事項注意事項

fstream 物件的取回指標並放置指標是 NOT 相互獨立的。如果取回指標移動,如此做放置指標。

範例

下列範例示範如何建立可以讀取和寫入的 basic_fstream 物件。

// basic_fstream_class.cpp
// compile with: /EHsc

#include <fstream>
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
    fstream fs("fstream.txt", ios::in | ios::out | ios::trunc);
    if (!fs.bad())
    {
        // Write to the file.
        fs << "Writing to a basic_fstream object..." << endl;
        fs.close();

        // Dump the contents of the file to cout.
        fs.open("fstream.txt", ios::in);
        cout << fs.rdbuf();
        fs.close();
    }
}
  

建構函式

basic_fstream

建構屬於 basic_fstream 類型的物件。

成員函式

關閉

關閉檔案。

is_open

判斷檔案是否為開啟狀態。

開啟

開啟檔案。

rdbuf

傳回儲存的資料流緩衝區的位址,型別指標 basic_filebuf<Elem,否則為 Tr>。

交換

交換這個物件的內容以另一個 basic_fstream 物件的內容。

需求

標題: <fstream>

命名空間: std

請參閱

參考

C++ 標準程式庫中的執行緒安全

iostream 程式設計

iostreams 慣例

其他資源

<fstream> 成員

basic_fstream 成員