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.
建構函式
初始化 basic_ifstream 物件的新執行個體。 |
成員函式
關閉檔案。 |
|
判斷檔案是否已開啟。 |
|
開啟檔案。 |
|
傳回預存的資料流緩衝區的位址。 |
|
交換內容的這basic_ifstream內容所提供的basic_ifstream。 |
運算子
會指定這個資料流物件的內容。 這是移動的工作分派涉及rvalue ,不會留下副本。 |
需求
標頭: <fstream>
Namespace: 標準