answersLogoWhite

0

You have to use the preprocessor directive fstream.h.

#include <fstream.h>

void main ()

{

ifstream inDataStream;//the stream to open excess to a file

inDataStrea.opem("fileName.txt");//to open an excess to the file fileName.txt (can be //any)

if (inDataStream.fail())//check if the file was opened successfully

{

cout << "Couldn't open the file!";

}

inDataStream << "Hello";// writing the word "Hello" in the file (can be any information)

inDataStream.close();//close the opened excess to the file

}

User Avatar

Wiki User

16y ago

What else can I help you with?

Related Questions

How do you remove a dll file that is open by other programs?

You have to close the other program first, because when a program has a file open, the system locks the file.


What are the three steps that must be taken when a file is used by a program?

1. Open the file, Process the file, Close the file


How can you open a separate program with Batch files and then close that program with Batch?

Batch file that opens a program waits 5 seconds then closes that program. For some reason I cannot get this batch to perform the open portion, wait, then the close portion in .... startup batch file hangs up on second command.


Method 'CopyFile' of object 'IFileSystem3' Failed?

This error is due to the write protection check if the destination file is open. If the file is open close that file, it Will fix the issue.


How to create a batch file and impliment it?

To create a batch file open notepad, textedit, or whatever editor you wish to use. Once open write your program, check for errors, and "make simple text." Save this program as whateveryouwant.bat. Open the file and the batch file will execute.


What is basic structure of file handling in c language?

open, read/write, close


What is the program which writes welcome to Nepal in a file?

To write &quot;Welcome to Nepal&quot; in a file, you can use a simple Python program. Here's an example: with open('welcome.txt', 'w') as file: file.write('Welcome to Nepal') This program opens a file named welcome.txt in write mode and writes the specified text to it. If the file does not exist, it will be created.


What is the proper method of opening a file for writing as binary file?

To open a file for writing as a binary file in Python, you should use the open() function with the mode set to 'wb'. This mode stands for &quot;write binary,&quot; allowing you to write binary data to the file. For example, you can use open('filename.bin', 'wb') to create and write to a binary file named filename.bin. Always remember to close the file using the close() method or by using a with statement to ensure proper resource management.


How do I write a C plus plus program to store my friends name in a file?

To write a C++ program that stores a friend's name in a file, you can use the &lt;fstream&gt; library. First, include the library and create an ofstream object to open a file for writing. Use the &lt;&lt; operator to write the friend's name to the file, then close the file. Here's a simple example: #include &lt;iostream&gt; #include &lt;fstream&gt; using namespace std; int main() { ofstream outFile(&quot;friends.txt&quot;); if (outFile.is_open()) { outFile &lt;&lt; &quot;Friend's Name\n&quot;; // Replace with the actual name outFile.close(); } else { cout &lt;&lt; &quot;Unable to open file&quot;; } return 0; }


What program can you use to open an abw file?

tinyword.com There, they provide the program needed to open an .ABW file.


How do you edit a existing file in c program?

Open the file for reading and load the content into memory where it can freely edited. To prevent external changes to the file, keep the file open but lock it to prevent access. When the user saves the modified data, write that data to a temporary file then close it. Then close the original file, delete it and rename the temporary file with the original file name. For added safety during file edits, you should also maintain a recovery file that keeps track of all the changes. Once the temporary is renamed, you can delete the recovery file.


What are the Unix system calls for Input and Output?

In Unix, the primary system calls for input and output are read(), write(), open(), close(), and lseek(). The open() call is used to open a file descriptor for reading or writing, while read() and write() perform the actual data transfer between the file descriptor and a buffer in memory. The close() call is used to close the file descriptor, and lseek() allows for repositioning the file pointer within the file. These calls provide a low-level interface for file and device I/O operations.