Nice description Bob. We are humans and text is much easier to read than,
days. Whether it takes 1/2 or a 2 milliseconds hardly makes any difference
unless you are reading a ton of data.
On Wed, 13 Sep 2006 01:43:02 -0700, Illuminator wrote:
CString a;
int b;
double c;
CString d;
What is the best way of doing this? I also need to write this variables
several times and store them to file.
As others have posted, you can write the values into a string and then
output that string to a text file using CStdioFile. You have the code
you need to do that, and the MSDN online library has examples of using
CStdioFile.
The important point here that you need to understand is why outputting
them in text format has (big) advantages and (small) disadvantages.
There's a small performance penalty when reading them back, because
the string has to parsed to extract the values. But that drawback is
(IMHO) massively outweighed by the advantage of textual resilience.
Consider what happens if you want to output the int number from a 32
bit little-endian machine, but have the data read by a 64 bit big
endian machine. Or your two machines have different floating-point
formats. Or the writing application is compiled for ANSI and the
reading one is compiled for UniCode. Do you get the picture? That
might not be the case today, but who knows what happens tomorrow?
The advantages of textual file formats don't begin and end with the
fact that they're human-readable, but that advantage is nothing to be
sniffed at when testing time rolls around.
For extra credit, you could even write them out in XML tagged-text
format, but that would be kind of overkill for this example :-)
--
Bob Moore
http://bobmoore.mvps.org/
(this is a non-commercial site and does not accept advertising)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Do not reply via email unless specifically requested to do so.
Unsolicited email is NOT welcome and will go unanswered.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~