Click to See Complete Forum and Search --> : How to read/write CString from/in CFile ?


May 9th, 1999, 02:53 PM
please help me, how can I read and write CStrings from/into CFiles ?
I tried e.g
pChar=LPCTSTR(sString);
pFile->Write(pChar, sString.GetLength()+1);
or
pFile->Write(sString, sString.GetLength());

and

pFile->Read(sString.GetBuffer(512), 512);
sString.ReleaseBuffer();

what is wrong ?
How can i write and retrieve that damned CStrings ?

Greetin'
Jay

shellreef
May 9th, 1999, 06:26 PM
Try using a CArchive, then

CArchive ar;
CString str;
ar << string;


to read:
ar >> string;

Harvey Hawes
May 9th, 1999, 10:08 PM
Hi,

Look at CStdioFile instead of CFile. It's designed to handle strings.

HTH,

Harvey Hawes

Software Engineer
BioScience Analysis Software Ltd.

Masters Candidate
Cardiovascular/Respiratory Sciences
Faculty of Medicine
University of Calgary
Calgary, Alberta, Canada