J
Joe Hesse
Hi,
I have a C++ function that writes to an ofstream object.
I would like to sometimes use it to write to cout.
I realize that cout is of type ostream which is not ofstream.
Since cout is "kind of" an output file, there should be someway to do it.
The following code shows what I am trying to do.
------------------------------------------------
#include <iostream>
#include <fstream>
using namespace std;
void foo(ofstream & out)
{
out << "Testing";
}
int main()
{
ofstream file("test.txt");
foo(file); // works
file.close();
foo(cout); // DOESN'T WORK
return 0;
}
I have a C++ function that writes to an ofstream object.
I would like to sometimes use it to write to cout.
I realize that cout is of type ostream which is not ofstream.
Since cout is "kind of" an output file, there should be someway to do it.
The following code shows what I am trying to do.
------------------------------------------------
#include <iostream>
#include <fstream>
using namespace std;
void foo(ofstream & out)
{
out << "Testing";
}
int main()
{
ofstream file("test.txt");
foo(file); // works
file.close();
foo(cout); // DOESN'T WORK
return 0;
}