此數(shù)據(jù)類型通常用來表示文件流,并且具有 stream 和 ifstream 的能力,也就是說它可以創(chuàng)建文件,向文件寫入信息和從文件讀取信息。
下面是 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 的別名。以下成員類型可以用作參數(shù)或由成員函數(shù)返回類型。
| 成員類型 | 定義 |
|---|---|
| char | 字符類型 |
| char_traits |
traits_type |
| int | const value_type |
| int | int_type |
| streampos | pos_type |
| streamoff | off_type |
下面是<fstream>中所有方法的列表,成員函數(shù) -
| 編號 | 描述和說明 |
|---|---|
| 1 | fstream::close - 關(guān)閉當(dāng)前與對象關(guān)聯(lián)的文件,將其與流分離。 |
| 2 | fstream::is_open - 返回當(dāng)前流是否與文件相關(guān)聯(lián)。 |
| 3 | fstream::open - 打開由參數(shù)filename標(biāo)識的文件,將其與流對象相關(guān)聯(lián)。 |
| 4 | fstream::operator= - 返回一個常量迭代器,它指向數(shù)組的開始。 |
| 5 | fstream::rdbuf - 返回指向內(nèi)部filebuf對象的指針。 |
| 6 | fstream::swap - 在 x 和 *this 之間交換所有內(nèi)部數(shù)據(jù)。 |
| 編號 | 描述和說明 |
|---|---|
| 1 | swap-free - 交換fstream對象x和y的值。 |