fstream - STL C++

basic_fstream<C,T>::basic_fstream()

Declaration

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

Description

This is the constructor for the basic_fstream class template.

Header Include

#include <fstream>

Overloads

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

Example

#include <iostream>
#include <fstream>

int main() {
	using namespace std;

	basic_fstream<char> qXoaXFile;
	// Open an ASCII text file for reading and writing.
	qXoaXFile.open("XoaX.txt", ios_base::out | ios_base::in | ios_base::trunc);

	if (qXoaXFile.is_open()) {
		// Write the string into the file
		qXoaXFile << "XoaX.net" << endl;

		// Set the reading location to the beginning of the file
		qXoaXFile.seekg(0);

		// Read the file back out
		cout << "Read from file: " << qXoaXFile.rdbuf() << endl;
		qXoaXFile.close();
	} else {
		cout << "\"XoaX.txt\" failed to open" << endl;
		return -1;
	}

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

Output

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

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