Click here to Skip to main content
15,882,152 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my project is in unicode mode and iam able to read unicode files by using Carchive ,

but same archive when iam reading ANSI files in unicode .its reading some junk values.

can u tell me how to read by using CFile ?

What I have tried:

CFile fileIn(_T("D:\\test.txt"), CFile::modeRead );
CArchive arcOut(&fileIn, CArchive::load);

CString str;
while (arcOut.ReadString(str))
{

}
arcOut.Close();
fileIn.Close();
Posted
Updated 25-Feb-16 23:06pm

1 solution

CArchive is not intended to read common text files. It is used to save and store a binary representation of the data used by your application (commonly the data hold by your CDocument class).

If you use the CArchive string functions, they will use Unicode strings with Unicode builds and multi byte strings with non Unicode builds.

If you want to read common text files, use any other file I/O method like CFile, streams, or the C standard library f functions to read the text as is (binary) into a buffer and convert aftwerwards if necessary (e.g. convert ANSI text to Unicode to be displayed with Unicode applications). See Handling simple text files in C/C++[^] for converting text to other encodings.
 
Share this answer
 
Comments
Member 11937050 26-Feb-16 5:49am    
CStidoFile CString ReadString it will read line by line ?
Jochen Arndt 26-Feb-16 5:55am    
Just read the documentation:
https://msdn.microsoft.com/en-us/library/x5t0zfyf.aspx

So it can be used like in your code. But note:

"The CString version of this function removes the '\n' if present; the LPTSTR version does not."

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900