Advertisement
2002ASP Files #7553

C++ File I/O Examples

This demonstrates an example of C++'s fstream File I/O. Very simple; the basic stuff for beginners to learn from. If you would like to see how to do something more in the direction this code leads, comment on (and rate) it telling me what specifically you want to see and I'll be glad to suffice.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
//
// lucky760@yahoo.com
//
#include <fstream>
const char *FILENAME = "FILE.txt";
int main() {
	//create output object associated w/ file
	ofstream fout(FILENAME);
	cout << "Enter your secret password: ";
	char str[60];
	cin >> str;
	//write to file
	fout << "This is your secret password. Don't give it to anyone!\n";
	fout << str;
	//close file
	fout.close();
	cout << endl;
	ifstream fin(FILENAME);
	char ch;
	while (fin.get(ch))
		cout << ch;
	fin.close();	
	return 0;
}
Original Comments (3)
Recovered from Wayback Machine