basic_ifstream 類別
描述物件項目的控制項擷取並輸入從類別 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>
命名空間: std