|
-
December 9th, 2004, 11:16 AM
#1
writing to screen AND disk:
Hello:
I am researching the code to write to both screen and to hard drive (file) simultaneously, if this is possible; I am aware that I can program cin to write to file on disk, but it will not appear on the screen (?). If I am taking input from a user and I wish to copy it, why can I not write to disk while it is printed to console before them also? I am unsure about this and I hope for some knowledgable insight into this operation.
Thank-you in advance for your assistance,
Matthew Mansoor
"Nay, you love this present life!"
Save your keystrokes!
-
December 9th, 2004, 11:41 AM
#2
Re: writing to screen AND disk:
Open an ifstream to the file you want to write to and output both to the screen and file.
Code:
#include <fstream>
#include <string>
using namespace std;
...
ifstream ifs;
ifs.open("somefile.txt", ios_base::out);
if (ifs.is_open())
{
string str;
// Get input from user in str
// Now, output to screen
cout << str;
// and output to file
ifs << str;
...
ifs.close();
}
-
December 9th, 2004, 11:45 AM
#3
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|