/*the fstream library allows us to work with files. To use The fstream library,include both the standard: <iostream>AND the <fstream> header file: Example: #include<iostream> #include<fstream> there are three classes included in the fstream Library. Which are used to Create,Write or read file: ofstream:Create and Writes to files. ifstream:Reads from files. fstream:A Combination of ofstream and ifstream:creates,reads,and writeto files.*/ /*******************************************************************************/ //Create and Write To File. #include<iostream> #include<fstream> using namespace std; int main() { //Create and open a text file. ofstream Myahmedfile("ahmedfile.txt"); //Write to the file. Myahmedfile << "Hello Ahmed Abdelmoneim"; //Close the file. Myahmedfile.close(); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter