The most frequent thing open a file with path name goes like this.
#include < fstream.h >
Current directory.
ofstream fout("TAtesting.txt");
Inside a folder of the current directory.
ofstream fout("Release/TAtesting.txt");
For 1 level up the current directory.
ifstream fin("..//..//TAtestingInput.rtf");
For 2 level up the current directory.
ifstream fin("..//..//TAtestingInput.rtf");
With path name specified.
ifstream fin("/Users/reza/Documents/workspace/TAtestingInput.rtf");
Same is true for output file.
ofstream fout("TAtestingOutput.txt");
To check whether the file is opened correctly.
cout<<"File is open "<< boolalpha<< fin.is_open()<< endl;
To write something inside the file instead of cout name of the file in the code.
fout<<"Here is something for the file as an output."<< endl;
Finally to close the file.
fin.close();
fout.close();
Subscribe to:
Post Comments (Atom)
Carlo Cipolla's Laws of Stupidity
"By creating a graph of Cipolla's two factors, we obtain four groups of people. Helpless people contribute to society but are...
-
To install pngwrite we need to install to helper library before we install pngwriter. 1. libpng 2. freetype2 We can use fink or macport to i...
-
"By creating a graph of Cipolla's two factors, we obtain four groups of people. Helpless people contribute to society but are...
-
Use 'Disk Utility' application to format the USB drive in MS-DOS (FAT) format Download the windows ISO file from the Windows websit...
1 comment:
File Handling in C++
File Handling concept is mainly used for store data permanently system or computer. Using file handling we can store our data in Secondary memory (Hard disk).
Post a Comment