fstream - STL C++

ifstream

Declaration

typedef basic_ifstream<char, char_traits<char> > ifstream;

Description

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

Header Include

#include <fstream>

Example

#include <iostream>
#include <fstream>

int main() {
	using namespace std;

	// Open the input file stream for reading
	ifstream qXoaXFile;
	qXoaXFile.open("XoaX.txt");

	if (qXoaXFile.is_open()) {
		// Read from the file
		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

ifstream Output
 

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