










































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











































Asif Nawaz University Institute of Information Technology, PMAS-AAUR
Asif Nawaz University Institute of Information Technology, PMAS-AAUR
Asif Nawaz University Institute of Information Technology, PMAS-AAUR
Asif Nawaz University Institute of Information Technology, PMAS-AAUR
Asif Nawaz University Institute of Information Technology, PMAS-AAUR Mr. Dave Clausen 7
Asif Nawaz University Institute of Information Technology, PMAS-AAUR
A file is opened for output for writing data into it and is also opened for input for reading data from it. Similarly, a file can also be opened fro both input and output operations.
Asif Nawaz University Institute of Information Technology, PMAS-AAUR
Asif Nawaz University Institute of Information Technology, PMAS-AAUR
Name Description ios::in Open file to read ios::out Open file to write ios::app All the date you write, is put at the end of the file. It calls ios::out ios::ate Moves the file pointer to the end of file when the file is opened. ios::trunc Deletes all previous content in the file. (empties the file) ios::nocreate If the file does not exist, opening it with the open() function gets impossible. ios::noreplace If the file exists, trying to open it with the open() function, returns an error. ios::binary Opens the file in binary mode.
Asif Nawaz University Institute of Information Technology, PMAS-AAUR
Asif Nawaz University Institute of Information Technology, PMAS-AAUR
#include <fstream.h> main() { ofstream outFile("file1.txt", ios::out); outFile << "That's new!\n"; outFile.close(); } If you want to set more than one open mode, just use the OR operator- |. This way: ios::ate | ios::binary
Asif Nawaz University Institute of Information Technology, PMAS-AAUR
#include <fstream.h> #include <fstream.h> main( ) main( ) { { ofstream file(“c:\fout.txt"); ofstream file(“c:\fout.txt"); file << "Hello World!"; file << "Hello World!"; fout.close(); fout.close(); return 0; return 0; } }
Asif Nawaz University Institute of Information Technology, PMAS-AAUR
Asif Nawaz University Institute of Information Technology, PMAS-AAUR
Asif Nawaz University Institute of Information Technology, PMAS-AAUR