fstream - STL C++

fstream

Declaration

typedef basic_fstream<char, char_traits<char> > fstream;

Description

This is the type definition of the fstream type in the fstream header.

Header Include

#include <fstream>

Example

#include <iostream>
#include <fstream>

int main() {
	using namespace std;

	fstream 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

fstream Output
 

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