Advertisement
ASP_Volume2 Files #40461

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

Résumé par IA: 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.

Code source
original-source
//
// [email protected]
//
#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;
}
Commentaires originaux (3)
Récupéré via Wayback Machine