basic_fstream Class

將告訴您的物件,控制插入與擷取的項目,並使用類別的資料流緩衝區的編碼的物件 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 物件的放入的指標都是相互獨立。取得滑鼠指標移動時,如果程式放入的指標。

範例

下列範例示範如何建立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();
    }
}
  

a33ahe62.collapse_all(zh-tw,VS.110).gif建構函式

basic_fstream

建構型別的物件basic_fstream

a33ahe62.collapse_all(zh-tw,VS.110).gif成員函式

關閉

關閉檔案。

is_open

判斷檔案是否已開啟。

開啟

開啟檔案。

rdbuf

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

交換

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

需求

標頭: <fstream>

Namespace: 標準

請參閱

參考

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

iostream 程式設計

iostreams 慣例

其他資源

<fstream> 成員

basic_fstream 成員