I was wondering. Is there a way to write something from one method in to a result file instead of outputting to screen?
To describe a little better, in pseudocode:
#include <iostream>
#include <fstream>
using namespace std;
class Inputoutput
{
private:
ifstream fileOne;
ofstream fileTwo;
int i;
//More variables here off course. Int's and stuff...
public:
// In the original program this method
// has an output to screen:
void outputFromFileToScreen()
{
fileOne.open("file.txt", ios::in);
for(i = 0; i < 16 && !fileOne.eof(); i ++)
{
fileOne.get(chars[i]);
} // end for
infile.close();
for(j = 0; j <i; j ++)
{
cout << (int) c[j];
} // end for
} // end methode
}; // end class
Now instead of outputting this to screen by calling this method from main I would like to do something like:
int main()
{
ofstream resultMethod;
resultMethod.open("resultFile.dat", ios::out);
resultMethod << io.del3(); // Pass the output to resultFile instead of screen?
} // end main
But trying this just gives a "no operator "<<" matches these operands". And I'm at a loss. Trying to find a tutorial that shows how to output stuff from methods to a file but I can't find anything...?