C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 17th, 2006, 11:54 AM
theforistellhic theforistellhic is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2006
Posts: 2 theforistellhic User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Template I/O?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT