unicode中的Carchive问题 [英] Carchive issue in unicode

查看:191
本文介绍了unicode中的Carchive问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目处于unicode模式,我可以通过使用Carchive读取unicode文件,

但是当我在unicode中读取ANSI文件时,同样存档。垃圾值。



你可以告诉我如何使用CFile阅读吗?



什么我试过了:



CFile fileIn(_T(D:\\test.txt),CFile :: modeRead);

CArchive arcOut(& fileIn,CArchive :: load);



CString str;

while(arcOut。 ReadString(str))

{



}

arcOut.Close();

fileIn.Close();

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();

推荐答案

CArchive 不用于读取常见文本文件。它用于保存和存储应用程序使用的数据的二进制表示形式(通常由 CDocument 类保存的数据)。



如果使用 CArchive 字符串函数,它们将使用带有Unicode构建和多字节字符串的Unicode字符串非Unicode构建。



如果要读取常见文本文件,请使用任何其他文件I / O方法,如 CFile ,streams或C标准库 f 函数将文本原样(二进制)读入缓冲区并在必要时进行转换(例如将ANSI文本转换为Unicode与Unicode应用程序一起显示)。请参阅使用C / C ++处理简单文本文件 [ ^ ] for将文本转换为其他编码。
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.


这篇关于unicode中的Carchive问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆