Jump to content

  • Log In with Google      Sign In   
  • Create Account

btower

Member Since 04 Jun 2004
Offline Last Active Yesterday, 08:27 AM

Topics I've Started

ostream_iterator with pointers

24 April 2008 - 11:13 AM

I want to use an ostream_iterator to write some save data to a file. I have a vector that contains my highscore objects: vector<HighScore *>
ofstream stream(savefile.c_str());
copy(scores->begin(), scores->end(), ostream_iterator<HighScore *>(stream));
I thought this was a nice way to write it, but I get the following problem: When I open the file, I see blocks of 32 bit integers written as hexadecimal, like this: 00035870000358F8 Obviously these are the address values of the pointers to the HighScore object. So my question is can I make the iterator work with pointer objects? Or is it required to make vector<HighScore> and not use pointers here. I have overloaded the << operator in HighScore: friend std::ostream & operator<< (std::ostream & o, const HighScore * h)

PARTNERS