首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::basic_ofstream::basic_ofstream

basic_ofstream();

(1)

?

explicit basic_ofstream( const char* filename, std::ios_base::openmode mode = ios_base::out );

(2)

?

explicit basic_ofstream( const std::filesystem::path::value_type* filename, std::ios_base::openmode mode = ios_base::out );

(3)

(since C++17)

explicit basic_ofstream( const std::string& filename, std::ios_base::openmode mode = ios_base::out );

(4)

(since C++11)

explicit basic_ofstream( const std::filesystem::path& filename, std::ios_base::openmode mode = ios_base::out );

(5)

(since C++17)

basic_ofstream( basic_ofstream&& other );

(6)

(since C++11)

basic_ofstream( const basic_ofstream& rhs) = delete;

(7)

(since C++11)

构造新的文件流。

1%29默认构造函数:构造与文件无关的流:默认构造std::basic_filebuf并使用指向此默认构造的指针构造基。std::basic_filebuf会员。

2-3%29首先执行与默认构造函数相同的步骤,然后通过调用将流与文件关联。rdbuf()->open(filename, mode |std::ios_base::out)28%见std::basic_filebuf::open有关调用%29的效果的详细信息。如果open()调用返回一个空指针,设置setstate(failbit)只在下列情况下提供过载%283%29std::filesystem::path::value_type不是char.%28自C++17%29

4-5%29basic_ofstream(filename.c_str(), mode)...

6%29移动构造函数。首先,将基类从other%28不影响rdbuf()指针%29,然后移动-构造std::basic_filebuf成员,然后调用this->set_rdbuf()安装新的basic_filebuf就像rdbuf()基类中的指针。

7%29复制构造函数被删除:该类不可复制.

参数

filename

-

the name of the file to be opened

mode

-

specifies stream open mode. It is bitmask type, the following constants are defined: Constant Explanation app seek to the end of stream before each write binary open in binary mode in open for reading out open for writing trunc discard the contents of the stream when opening ate seek to the end of stream immediately after open

Constant

Explanation

app

seek to the end of stream before each write

binary

open in binary mode

in

open for reading

out

open for writing

trunc

discard the contents of the stream when opening

ate

seek to the end of stream immediately after open

Constant

Explanation

app

seek to the end of stream before each write

binary

open in binary mode

in

open for reading

out

open for writing

trunc

discard the contents of the stream when opening

ate

seek to the end of stream immediately after open

other

-

another file stream to use as source

二次

代码语言:javascript
复制
#include <fstream>
#include <utility>
#include <string>
int main()
{
    std::ofstream f0;
    std::ofstream f1("test.bin", std::ios::binary);
    std::string name = "example.txt";
    std::ofstream f2(name);
    std::ofstream f3(std::move(f1));
}

二次

另见

open

opens a file and associates it with the stream (public member function)

open

opens a file and configures it as the associated character sequence (public member function of std::basic_filebuf)

set_rdbuf

replaces the rdbuf without clearing its error state (protected member function)

(constructor)

constructs the object (public member function of std::basic_ostream)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com