File modes: – A constructor ifstream and function open() are used to create files as well as open the existing files in the default text mode. In both method, only arguments used is the file name. C++ provides a mechanism of opening a file in different mode in which case the second parameter must be explicitly passed. There are number of modes. Used with ifstream constructor. Syntax of the constructor is –
<Stream Object>.open(“File Name”,Mode);
File modes are as follows: –
Mode value |
Effect on the mode |
i. Ios::in | i. Open for reading |
ii. Ios::out | ii. Open for writing |
iii. Ios::ate | iii. Seek to the end of file at opening time |
iv. Ios::app | iv. Append mode for writing file at the end of the file |
v. Ios::trunc | v. Truncate the file if file already the exist |
vi. Ios::nocreate | vi. Open fails if the file does not exit |
vii. Ios::noreplace | vii. Open fails if the file already exist |
viii. Ios::binary | viii. Open a file in binary mode |
You must be logged in to post a comment.