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
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();
}
Re: writing to screen AND disk:
Marc:
Cool :p Thank-you very much. I will try this today. Excellent. ;)
Matthew Mansoor