m1n

Hi,

i have one CString variable, and i have one file, about 600 characters, i try to put all the data file in the Cstring, my algorithm is :

Code Snippet

CString strTemp;
while( ar.ReadString(strTemp) )
m_strFileBuffer += strTemp + _T(" ");


ar is CArchive.

Proble is that: when algorithm go few times throught 'ReadString' data readed in 'strTemp' are not aded to 'm_strFileBuffer'.

The data in strTemp is readed well, but it is not added in m_strFileBuffer.

Anyone can help with that : )

Thanks.


Re: Visual C++ General CString

Aleksandr Tokarev

Can you show us detailed output, I mean:

print strTemp, and m_strFileBuffer at every iteration. Somthing like this:

strTemp: 'a'

m_strFileBuffer: 'a '

strTemp: 'b'

m_strFileBuffer: 'a b '

etc.

Thanks.





Re: Visual C++ General CString

Holger Grund

That sounds a bit like embedded \0 in the archive strings. Not sure, how CArchive encodes strings, but if it simply stores a length-prefixed buffer, embedded \0s would likely cause the symptoms you describe.

-hg





Re: Visual C++ General CString

Simple Samples

You can read the entire file with one read function call; see my Edit Control Read. If you must have a single space between each record then you will need to convert the two end of line characters ("\r\n") into one space.

You cannot however do this using the CArchive file. There is a way to do something similar using the CArchive file but I forget the details except that the MFC source code for CEditView has an OnOpenFile override.






Re: Visual C++ General CString

Viorel.

In my opinion, if your file was not written using CArchive (i.e. it is a simple text file), you cannot always read it with CArchive. In case of simple text files you can use the CStdioFile class and ReadString member.

I hope this makes sense. Can you confirm that your source file was created with CArchive





Re: Visual C++ General CString

Simple Samples

Viorel. wrote:

In my opinion, if your file was not written using CArchive (i.e. it is a simple text file), you cannot always read it with CArchive.

Have you read the CArchive documentation I am surprised you would say that if you had. Just look at the CArchive member functions.