畏缩,我得到的是方形框而不是文字
嗨.
我是一个使用任何形式的C语言的完全菜鸟(在vb6中工作了4年),所以我希望有人可以帮助我.
我设法解锁了运行在wince 5上的RAC Satnav,因此我下载了嵌入式c ++ 4.在文本框中.
我一直在使用以下代码,看上去确实可以读取文件,但我在文本框中得到的只是一堆小方块字符.我怀疑这与Unicode有关吗?
Hi.
I''m a complete noobe with any form of the c language (4 years in vb6) so I''m hoping someone can help me out.
I''ve managed to unlock my RAC Satnav which runs on wince 5 so I''ve downloaded embedded c++ 4. Got to start somewhere so I''ve tried to write something that can read a line from a text file and display it in a text box.
I''ve been using the following code which does appear to read the file OK but all I get in the text box is a bunch of little square characters. I suspect this is something to do with Unicode?
CFile file;
CString line;
if (file.Open(_T("\\ResidentFlash\\text.txt"), CFile::modeRead)) {
CArchive ar(&file, CArchive::load);
while (ar.ReadString(line)) {
CEdit * pEdit = (CEdit *)GetDlgItem(IDC_EDIT1);
CString strEdit = (line) + _T("test");
pEdit->SetWindowText(strEdit);
}
ar.Close();
file.Close();
带引号的测试"按原样出现,但我认为应该在(行)中的文本是显示为小方框的部分.
有人可以提供帮助吗,我已经在Google上搜索了几篇相关文章,但它们都是针对c ++的,对于嵌入式c ++和wince,我找不到任何东西. c ++与wince并不完全兼容.
The quoted "test" appears as it should but the text that I believe should be in (line) is the part that appears as little square boxes.
Can someone please offer assistance, Ive searched on Google and found several related articles but they were for c++, I cant find anything for embedded c++ and wince. c++ is not completely compatible with wince.
您的文件很有可能是ANSI而不是UNICODE,在这种情况下,您应该将其读入ANSI字符串.
[在OP评论后编辑]
请参见《 C ++字符串完整指南,第一部分-Win32字符编码》 [
Hi,
It is very likely that your file is ANSI and not UNICODE, in that case you should read it into an ANSI string.
See The Complete Guide to C++ Strings, Part I - Win32 Character Encodings[^] and part 2, for string handling tutorial.
eVC4 MFC does not supportCStringA
andCStringW
, so you have to handle ANSI strings with the Standard C++ Library, and convert to UNICODE before callingCEdit
. The following compiles OK with VS2008, hopefully will do it with eVC:
#include <fstream>
#include <string>
inline void Test()
{
std::ifstream in(_T("\\ResidentFlash\\text.txt"));
std::string line;
std::getline(in, line);
CString strEdit(line.c_str());
CEdit * pEdit = (CEdit *)GetDlgItem(IDC_EDIT1);
pEdit->SetWindowText(strEdit + _T("test"));
}
[/编辑]
尝试将UNICODE文件复制到设备上,程序应读取该文件.
欢呼声,
AR
[/Edit]
Try to copy a UNICODE file to your device, your program should read it.
cheers,
AR
int FetchData(const string strFile)
{
FILE * _tempFile;
char _buff[100];
cout << "FetchData file name is " << strFile << endl;
_tempFile = fopen( strFile.c_str() , "r");
if (_tempFile == NULL) //file no exist
{
perror(" Open the data file error");
return -1;
}
if ((fseek(_tempFile , 0L, SEEK_SET)) < 0)
{
perror("File seek error");
fclose(_tempFile);
return -2;
}
while(fgets(_buff,100,_tempFile)!=NULL)
{
DoSomeThingWithThisLine(_buff);
}
fclose(_tempFile);
return 1;
}
据我所知,WinCe的默认字符编码为UNICODE,根本不支持ANSI.通常,您不需要使用在WinCE中创建或通过同步转换的文本文件处理ANSI字符串.如果您需要通过转闪存卡或其他方式传输的文件,则可以使用 MultiByteToWideChar(...) [ ^ ]函数从文件读取后,将ANSI转换为UNICODE.
As far as I remember, WinCe''s default character encoding is UNICODE and ANSI is not supported at all. You normally don''t need to handle ANSI strings with text files created in WinCE or converted by synchronization. If you need the files transferred via transflash card or by other means, you can probably use MultiByteToWideChar(...)[^] function for ANSI to UNICODE conversion just after reading from file.