Re: saving std::string to a file
- From: "Ron Francis" <ronfrancis@xxxxxxxxxxx>
- Date: Tue, 22 Apr 2008 19:48:49 +0930
The next time you do a redesign, you might consider making all of your
classes derive from some common base class that has Serialize and
Deserialize methods. Then, you can write a CPoint::Serialize that knows
how to write the object to a stream, and a CPoint::Deserialize that knows
how to recreate the object from a stream. Once you do that, you won't be
dependent on the internal format. You could change the struct to use a
std::string, as long as the Serialize function writes the length first.
--
Tim Roberts, timr@xxxxxxxxx
Providenza & Boekelheide, Inc.
Hi Tim,
My main concern is char becoming obsolete.
It's an interesting approach you suggested because that's how I was doing it
in the first place.
I was looping through the array and each CPoint was saving itself., but as
the array became bigger, serializing became slower until I had to look at
it. The easy fix was to just write the whole array in one go.
I guess I could have optimised in other areas, but it was quick and allowed
me to get on with other things.
Anyway, thanks for confirming that using std:string has those limitations.
Ron.
.
- Follow-Ups:
- Re: saving std::string to a file
- From: David Wilkinson
- Re: saving std::string to a file
- References:
- saving std::string to a file
- From: Ron Francis
- Re: saving std::string to a file
- From: Tim Roberts
- saving std::string to a file
- Prev by Date: Re: Distributing msvcrt.dll
- Next by Date: Re: saving std::string to a file
- Previous by thread: Re: saving std::string to a file
- Next by thread: Re: saving std::string to a file
- Index(es):
Relevant Pages
|