answersLogoWhite

0

To have your program output to a file you must do the following :

First you must write the library that allows the use of files

#include

This will allow you to use the necessary codes to input or output to files

Then in your program you write the following code

ofstream outfile("statistic.txt");

This declares the assigned file for output. Here statistic.txt is the assign file. The program will send the output to that file.

To send the output to the assigned file instead of the screen do the following:

Instead of "cout <<" write out what you put in the previous code "outfile << "

ofstream outfile("statistic.txt");

The bold part determines what you put instead of cout. In this case it was outfile but it can be named whatever you want

Finally at the end of the program you must close it using the following statement:

outfile.close();

User Avatar

Wiki User

15y ago

Still curious? Ask our experts.

Chat with our AI personalities

MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine
BlakeBlake
As your older brother, I've been where you are—maybe not exactly, but close enough.
Chat with Blake
CoachCoach
Success isn't just about winning—it's about vision, patience, and playing the long game.
Chat with Coach

Add your answer:

Earn +20 pts
Q: How do you assign output in C plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp