C++ 庫 - <fstream>



簡介

此資料型別通常表示檔案流,並且具有 ofstream 和 ifstream 的功能,這意味著它可以建立檔案、將資訊寫入檔案以及從檔案讀取資訊。

定義

以下是 std::fstream 的定義。

template<
   class CharT, 
   class Traits = std::char_traits<CharT>> 
class basic_fstream : public std::basic_iostream<CharT, Traits>

引數

  • charT - 作為成員 char_type 的別名。

  • traits - 作為成員 traits_type 的別名。

成員型別

以下成員型別可以用作成員函式的引數或返回型別。

序號 成員型別 定義
1 char 字元型別
2 char_traits<char> traits_type
3 int const value_type
4 int int_type
5 streampos pos_type
6 streamoff off_type

來自 <fstream> 的函式

以下是 <fstream> 中所有方法的列表

成員函式

序號 方法和描述
1 fstream::close

關閉當前與物件關聯的檔案,將其與流分離。

2 fstream::is_open

返回流當前是否與檔案關聯。

3 fstream::open

開啟引數 filename 指定的檔案,將其與流物件關聯。

4 fstream::operator=

返回一個指向陣列開頭的常量迭代器。

5 fstream::rdbuf

返回指向內部 filebuf 物件的指標。

6 fstream::swap

交換 x 和 *this 之間的所有內部資料。

非成員過載函式

序號 方法和描述
1 swap-free

交換 fstream 物件 x 和 y 的值。

廣告