fstream - STL C++

basic_ofstream<C,T>::basic_ofstream()

Declaration

template <class C, class T = char_traits<C> >
basic_ofstream<C,T>::basic_ofstream();

Description

This is the constructor for the basic_ofstream class template.

Header Include

#include <fstream>

Overloads

explicit basic_ofstream<C,T>::basic_ofstream(const char* kcpFilename,
			ios_base::openmode qOpenMode = ios_base::out);

Example

#include <iostream>
#include <fstream>

int main() {
	using namespace std;

	// Open the output file stream for writing
	basic_ofstream<char> qXoaXFile;
	qXoaXFile.open("XoaX.txt");

	if (qXoaXFile.is_open()) {
		// Write to the file
		qXoaXFile << "XoaX.net";
		qXoaXFile.close();
		cout << "Wrote \"XoaX.net\" to the file \"XoaX.txt\"." << endl;
	} else {
		cout << "\"XoaX.txt\" failed to open" << endl;
		return -1;
	}

	// Keep the window open
	cin.get();
	return 0;
}

Output

basic_ofstream<C,T>::basic_ofstream() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.