共用方式為


basic_ifstream Class

描述控制擷取項目的物件和類別的資料流緩衝區中的編碼的物件 basic_filebuf<Elem, Tr>,型別的項目與Elem,其字元特性由類別Tr。

template <class Elem, class Tr = char_traits<Elem> >
    class basic_ifstream : public basic_istream<Elem, Tr>

參數

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

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

備註

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

範例

下列範例會示範如何在文字檔中讀取。

// basic_ifstream_class.cpp
// compile with: /EHsc

#include <fstream>
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
    ifstream ifs("basic_ifstream_class.txt");
    if (!ifs.bad())
    {
        // Dump the contents of the file to cout.
        cout << ifs.rdbuf();
        ifs.close();
    }
}

輸入: basic_ifstream_class.txt

This is the contents of basic_ifstream_class.txt.

Output

This is the contents of basic_ifstream_class.txt.

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

basic_ifstream

初始化 basic_ifstream 物件的新執行個體。

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

關閉

關閉檔案。

is_open

判斷檔案是否已開啟。

開啟

開啟檔案。

rdbuf

傳回預存的資料流緩衝區的位址。

交換

交換內容的這basic_ifstream內容所提供的basic_ifstream

k7hz8258.collapse_all(zh-tw,VS.110).gif運算子

operator=

會指定這個資料流物件的內容。 這是移動的工作分派涉及rvalue ,不會留下副本。

需求

標頭: <fstream>

Namespace: 標準

請參閱

參考

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

iostream 程式設計

iostreams 慣例

其他資源

<fstream> 成員

basic_ifstream 成員