
April 17th, 2006, 11:54 AM
|
|
Registered User
|
|
Join Date: Apr 2006
Posts: 2
Time spent in forums: 43 m 7 sec
Reputation Power: 0
|
|
|
Template I/O?
I'm making a game that will have a function to save a game, and then there is another function to read in that very same information to resume the game.
Is it possible to combine those functions, such that it could be just pass what form of iostream I want and do it.
example below:
Code:
#include <fstream>
using namespace std;
void stream(iostream type, int & foo);
int main()
{
int blah;
ifstream fin;
fin.open("fake.txt");
ofstream out;
out.open("fakage.txt");
if( !fin.fail() )
{
stream(fin, blah); //Calls function stream and inputs an int and then
//returns it as foo.
stream(out, blah); //Calls same function but this time outputs blah to
//the file.
}
fin.close();
out.close();
return 0;
}
void stream(iostream type, int & foo)
{
type << foo; //Problem is how to handle arrow?!
return;
}
My main question would be then if everything else is setup correctly, how do I handle the arrows to show which direction the stream is flowing.
Thanks for any help possible.
Tim
[edit] I asked my instructor and he told me just to overload the << operator to make it act like >>. So once he told me that it was easy.
|