定义于头文件 <fstream>
| template<     class CharT, | 
 类模板 basic_fstream 实现基于文件的流上的高层输入/输出。它将 std::basic_iostream 的高层接口赋予基于文件的缓冲( std::basic_filebuf )。
std::basic_fstream 的典型实现只保有一个非导出数据成员: std::basic_filebuf<CharT, Traits> 的实例。

亦定义二个对于常用字符类型的特化:
| 类型 | 定义 | 
| fstream | basic_fstream<char> | 
| wfstream | basic_fstream<wchar_t> | 
成员函数
移动文件流
std::basic_fstream<CharT,Traits>::operator=| basic_fstream& operator=( basic_fstream&& other ); | (C++11 起) | 
 移动赋值文件流 other 给 *this ,等效地移动赋值 std::basic_iostream 基类和关联的 std::basic_filebuf 。
将 other 置为无关联文件。注意基类移动赋值交换 *this 与 other 间的所有流状态变量(除了 rdbuf )。
参数
| other | - | 要移动的文件流。 | 
返回值
*this
调用示例
#include <fstream>
#include <utility>
#include <string>
#include <iostream>
int main()
{
    std::fstream fstream1("test1.txt", std::ios::out);
    std::cout << "fstream1 is: "
              << (fstream1 ? "true" : "false") << std::endl;
    fstream1 << "hello" << " ";
    std::cout << std::endl;
    //移动赋值文件流 other 给 *this ,
    //等效地移动赋值 std::basic_ostream 基类和关联的 std::basic_filebuf 。
    std::fstream fstream2 = std::move(fstream1);
    std::cout << "fstream1 is: "
              << (fstream1.is_open() ? "true" : "false") << std::endl;
    std::cout << "fstream2 is: "
              << (fstream2.is_open() ? "true" : "false") << std::endl;
    fstream2 << "word" << "!";
    std::cout << std::endl;
    fstream1.close();
    fstream2.close();
    std::fstream fstream3("test1.txt", std::ios::in);
    std::cout << "fstream3 is: "
              << (fstream3.is_open() ? "true" : "false") << std::endl;
    if (fstream3.is_open())
    {
        std::cout << fstream3.rdbuf() << std::endl;
    }
    std::cout << std::endl;
    return 0;
}输出

交换二个文件流
std::basic_fstream<CharT,Traits>::swap| void swap( basic_fstream& other ); | (C++11 起) | 
交换流与 other 的状态。
通过调用 basic_iostream<CharT, Traits>::swap(other) 和 rdbuf()->swap(other.rdbuf()) 进行。
参数
| other | - | 要交换状态的流 | 
返回值
(无)
调用示例
#include <fstream>
#include <utility>
#include <string>
#include <iostream>
int main()
{
    std::fstream fstream1("test1.txt", std::ios::out);
    std::cout << "fstream1 is: "
              << (fstream1 ? "true" : "false") << std::endl;
    std::fstream fstream2("test2.txt", std::ios::out);
    std::cout << "fstream2 is: "
              << (fstream2 ? "true" : "false") << std::endl;
    std::cout << std::endl;
    fstream1 << "hello 1" << " ";
    fstream2 << "hello 2" << " ";
    //交换流与 other 的状态。
    //通过调用 basic_ostream<CharT, Traits>::swap(other)
    //和 rdbuf()->swap(other.rdbuf()) 进行。
    std::cout << "fstream1.swap(fstream2) " << std::endl;
    fstream1.swap(fstream2);
    fstream1 << "hello 1" << " ";
    fstream2 << "hello 2" << " ";
    fstream1.close();
    fstream2.close();
    std::cout << std::endl;
    std::fstream fstream3("test1.txt", std::ios::in);
    std::cout << "fstream3 is: "
              << (fstream3.is_open() ? "true" : "false") << std::endl;
    if (fstream3.is_open())
    {
        std::cout << fstream3.rdbuf() << std::endl;
    }
    std::cout << std::endl;
    std::fstream fstream4("test2.txt", std::ios::in);
    std::cout << "fstream2 is: "
              << (fstream4.is_open() ? "true" : "false") << std::endl;
    if (fstream4.is_open())
    {
        std::cout << fstream4.rdbuf() << std::endl;
    }
    std::cout << std::endl;
    return 0;
}输出

返回底层未处理的文件设备对象
std::basic_fstream<CharT,Traits>::rdbuf| std::basic_filebuf<CharT, Traits>* rdbuf() const; | (C++11 起) | 
返回指向底层未处理文件设备对象的指针。
参数
(无)
返回值
指向底层未处理文件设备对象的指针。
调用示例
同上



















