I use Visual C++ but I was wondering if there is a way to output text to a file as well as having it appear of the screen when you execute the program and only used one line of code instead of two.
Here is a sample of the code that I did to make it appear on both the Screen when executed and be copied into the text file:
1. cout<<"ATV OFFROAD FURY CHAMPIONSHIP";
2. fout<<"ATV OFFROAD FURY CHAMPIONSHIP";
3. cout<<"Enter Burke's Finishes(enter 6 when done)";
4. fout<<"Enter Burke's Finishes(enter 6 when done)";
Line 1 and 3 output it to the screen and line 2 and 4 output it to the text file. If there a way to make it so that it does both in one line?
Hope that wasn't too confusing
Edited by - GR00316 on October 6, 2001 1:36:56 PM
Edited by - GR00316 on October 6, 2001 1:38:27 PM
Simple Question about Outputting Text to file in C++
Instead of doing it in one line you could make a function that does both. The function would take a string as a parameter and would print that string to the screen and then to the file.
void PrintAndSave(string message);
void PrintAndSave(string message)
{
cout << message;
fout << message;
}
void PrintAndSave(string message);
void PrintAndSave(string message)
{
cout << message;
fout << message;
}
You can redirect the output of the streams. Take a look at the setting rdbuf() (I don''t have my ref book with me rite now)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement