![]() |
In C++, we can open a file to perform read and write operations and close it when we are done. This is done with the help of fstream objects that create a stream to the file for input and output. In this article, we will learn how to open and close a file in C++. Open and Close a File in C++The fstream class contains the std::fstream::open() function that can be used to open files in different modes. Syntax of fstream::open()fstream_object.open(filename, mode); The modes can be of three types:
We can close the file using std::fstream::close() function. Algorithm
C++ Program to Open and Close a FileC++
Output
File opened successfully. File closed. |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |