std::basic_ofstream<CharT,Traits>::basic_ofstream

Constructs new file stream.

# Declarations

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

(since C++17)

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

(since C++11)

template< class FsPath >
explicit basic_ofstream( const FsPath& filename,
std::ios_base::openmode mode
= std::ios_base::out );

(since C++17)

basic_ofstream( basic_ofstream&& other );

(since C++11)

basic_ofstream( const basic_ofstream& rhs ) = delete;

(since C++11)

# Parameters

# Example

#include <fstream>
#include <string>
#include <utility>
 
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));
}

# Defect reports

DRApplied toBehavior as publishedCorrect behavior
LWG 3430C++17std::filesystem::path overload led to unwanted conversionsavoided by making it a template

# See also