
(MFC)要怎么才能读取Unicode 编码的文本??(Unicode环境)
(MFC)要怎么才能读取Unicode编码的文本?(Unicode环境)我希望读入后转成wchar_t*再进行处理~问题补充:能写下代码出来吗?CFilecfile;cf...
(MFC)要怎么才能读取Unicode 编码的文本?(Unicode环境)
我希望读入后转成wchar_t*再进行处理~问题补充:
能写下代码出来吗?
CFile cfile;
cfile.Open(fileway,CFile::moderead);
然后怎么读?
大哥 我想整个Unicode读完 所以参照了 http://apps.hi.baidu.com/share/detail/4914931 写了以下代码
void CUTOADlg::OnUToA(CString fileway)
{
CStdioFile file2;
file2.Open(fileway,CStdioFile::modeReadWrite);
CString str;
vector<CString> word_save;
while(file2.ReadString(str))
{//连续读取文件
word_save.push_back(str);
}
file2.Close();
for(int oop=0;oop!=word_save.size();++oop)
{
CString word;
word=word_saveoop;
MessageBox(word);
}
}
读了一个用文本弄出的Unicode编码文本 可是读出来的是乱码来的 为什么的?来自 http://zhidao.baidu.com/question/221489575.html 的问题
曾尝试:
CStdioFile file;
wchar_t wstr[100];
file.Open(fileway, CFile::modeRead);
//读一行
file.ReadString(wstr, 100);
//读指定数目
file.Read(wstr, 100);
file.Close();
CString wordout=wstr;
MessageBox(wordout);
仍然是乱码 求救!!
是直接在文本里面输入东西然后另存为Unicode编码的!该怎么读
是直接在文本里面输入些字符 然后另存为Unicode编码的文本! 该怎么读
我希望读入后转成wchar_t*再进行处理~
回复 L_o_o_n_i_e:
CFile file;
file.Open(fileway,CFile::modeRead);
file.Seek(3,0);
int len = file.GetLength();
char *buf = new char[len+1];
file.Read(buf,len-3);//用char接收读出来的东西,
buf[len] = 0;
wchar_t* wbuf=(wchar_t*)buf;//强制转过来
CString word;
word=wbuf;
file.Close();
MessageBox(word);
还是乱码啊~~!! 展开
我希望读入后转成wchar_t*再进行处理~问题补充:
能写下代码出来吗?
CFile cfile;
cfile.Open(fileway,CFile::moderead);
然后怎么读?
大哥 我想整个Unicode读完 所以参照了 http://apps.hi.baidu.com/share/detail/4914931 写了以下代码
void CUTOADlg::OnUToA(CString fileway)
{
CStdioFile file2;
file2.Open(fileway,CStdioFile::modeReadWrite);
CString str;
vector<CString> word_save;
while(file2.ReadString(str))
{//连续读取文件
word_save.push_back(str);
}
file2.Close();
for(int oop=0;oop!=word_save.size();++oop)
{
CString word;
word=word_saveoop;
MessageBox(word);
}
}
读了一个用文本弄出的Unicode编码文本 可是读出来的是乱码来的 为什么的?来自 http://zhidao.baidu.com/question/221489575.html 的问题
曾尝试:
CStdioFile file;
wchar_t wstr[100];
file.Open(fileway, CFile::modeRead);
//读一行
file.ReadString(wstr, 100);
//读指定数目
file.Read(wstr, 100);
file.Close();
CString wordout=wstr;
MessageBox(wordout);
仍然是乱码 求救!!
是直接在文本里面输入东西然后另存为Unicode编码的!该怎么读
是直接在文本里面输入些字符 然后另存为Unicode编码的文本! 该怎么读
我希望读入后转成wchar_t*再进行处理~
回复 L_o_o_n_i_e:
CFile file;
file.Open(fileway,CFile::modeRead);
file.Seek(3,0);
int len = file.GetLength();
char *buf = new char[len+1];
file.Read(buf,len-3);//用char接收读出来的东西,
buf[len] = 0;
wchar_t* wbuf=(wchar_t*)buf;//强制转过来
CString word;
word=wbuf;
file.Close();
MessageBox(word);
还是乱码啊~~!! 展开
4个回答
展开全部
头文件中要定义过
#define _UNICODE
这是最主要的,这样编译时会用 unicode 库。
class CString 使用 TCHAR data 类型, 本身就支持 unicode.
程序里用 宏 _T 转换普通字符串 到 unicode
程序里用 TCHAR 代替原来用的char.
用LPTSTR 代替原来用的 char*
用LPCTSTR 代替原来用的 const char*.
#define _UNICODE
这是最主要的,这样编译时会用 unicode 库。
class CString 使用 TCHAR data 类型, 本身就支持 unicode.
程序里用 宏 _T 转换普通字符串 到 unicode
程序里用 TCHAR 代替原来用的char.
用LPTSTR 代替原来用的 char*
用LPCTSTR 代替原来用的 const char*.
展开全部
我写了下面的代码,你自己根据下面这段代码自己改改:
============================
void CBaiduUseMfcMBDlg::OnBnClickedOk()
{
WIN32_FIND_DATAW FindFileData;
HANDLE hFind;
char serverPath1_Mbs[MAX_PATH];
wchar_t serverPath1_Unicode[10240];
wchar_t serverPath1_FindFirstUse[10240];
wchar_t serverPath1_ForDelete[10240];
DWORD dwError = 0;
//此处拷贝你的参数到serverPath1_Mbs中
strcpy(serverPath1_Mbs,"D:\\中文目录下的文件哦\\");
memset(serverPath1_Unicode,0x0,10240*2);
memset(serverPath1_FindFirstUse,0x0,10240*2);
//此处将char*转换为wchar_t*
::MultiByteToWideChar(
CP_ACP,
MB_COMPOSITE,
serverPath1_Mbs,
strlen(serverPath1_Mbs),
serverPath1_Unicode,
10240);
//下面调用win32的带"W"字母结尾的函数来执行所有宽字节参数的处理
wcscpy(serverPath1_FindFirstUse,serverPath1_Unicode);
wcscat(serverPath1_FindFirstUse,L"*.*");
hFind = ::FindFirstFileW( serverPath1_FindFirstUse, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
{
::MessageBoxW(NULL,L"查找文件发生错误!",L"错误",MB_OK|MB_ICONERROR);
return;
}
else
{
if ( wcscmp(FindFileData.cFileName,L".") != 0 &&
wcscmp(FindFileData.cFileName,L"..") != 0 &&
FindFileData.dwFileAttributes && FILE_ATTRIBUTE_DIRECTORY != 0 )
{
wcscpy(serverPath1_ForDelete,serverPath1_Unicode);
wcscat(serverPath1_ForDelete,FindFileData.cFileName);
if ( ! ::DeleteFileW(serverPath1_ForDelete) )
{
dwError = ::GetLastError();
::MessageBoxW(NULL,L"删除文件发生错误",L"错误",MB_OK|MB_ICONERROR);
}
}
while ( 0 != ::FindNextFileW(hFind,&FindFileData) )
{
if ( wcscmp(FindFileData.cFileName,L".") != 0 &&
wcscmp(FindFileData.cFileName,L"..") != 0 &&
FindFileData.dwFileAttributes && FILE_ATTRIBUTE_DIRECTORY != 0 )
{
wcscpy(serverPath1_ForDelete,serverPath1_Unicode);
wcscat(serverPath1_ForDelete,FindFileData.cFileName);
if ( ! ::DeleteFileW(serverPath1_ForDelete) )
{
dwError = ::GetLastError();
::MessageBoxW(NULL,L"删除文件发生错误",L"错误",MB_OK|MB_ICONERROR);
}
}
}
dwError = GetLastError();
FindClose(hFind);
if (dwError != ERROR_NO_MORE_FILES)
{
::MessageBoxW(NULL,L"循环查找文件发生错误",L"错误",MB_OK|MB_ICONERROR);
}
return;
}
}
============================
void CBaiduUseMfcMBDlg::OnBnClickedOk()
{
WIN32_FIND_DATAW FindFileData;
HANDLE hFind;
char serverPath1_Mbs[MAX_PATH];
wchar_t serverPath1_Unicode[10240];
wchar_t serverPath1_FindFirstUse[10240];
wchar_t serverPath1_ForDelete[10240];
DWORD dwError = 0;
//此处拷贝你的参数到serverPath1_Mbs中
strcpy(serverPath1_Mbs,"D:\\中文目录下的文件哦\\");
memset(serverPath1_Unicode,0x0,10240*2);
memset(serverPath1_FindFirstUse,0x0,10240*2);
//此处将char*转换为wchar_t*
::MultiByteToWideChar(
CP_ACP,
MB_COMPOSITE,
serverPath1_Mbs,
strlen(serverPath1_Mbs),
serverPath1_Unicode,
10240);
//下面调用win32的带"W"字母结尾的函数来执行所有宽字节参数的处理
wcscpy(serverPath1_FindFirstUse,serverPath1_Unicode);
wcscat(serverPath1_FindFirstUse,L"*.*");
hFind = ::FindFirstFileW( serverPath1_FindFirstUse, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
{
::MessageBoxW(NULL,L"查找文件发生错误!",L"错误",MB_OK|MB_ICONERROR);
return;
}
else
{
if ( wcscmp(FindFileData.cFileName,L".") != 0 &&
wcscmp(FindFileData.cFileName,L"..") != 0 &&
FindFileData.dwFileAttributes && FILE_ATTRIBUTE_DIRECTORY != 0 )
{
wcscpy(serverPath1_ForDelete,serverPath1_Unicode);
wcscat(serverPath1_ForDelete,FindFileData.cFileName);
if ( ! ::DeleteFileW(serverPath1_ForDelete) )
{
dwError = ::GetLastError();
::MessageBoxW(NULL,L"删除文件发生错误",L"错误",MB_OK|MB_ICONERROR);
}
}
while ( 0 != ::FindNextFileW(hFind,&FindFileData) )
{
if ( wcscmp(FindFileData.cFileName,L".") != 0 &&
wcscmp(FindFileData.cFileName,L"..") != 0 &&
FindFileData.dwFileAttributes && FILE_ATTRIBUTE_DIRECTORY != 0 )
{
wcscpy(serverPath1_ForDelete,serverPath1_Unicode);
wcscat(serverPath1_ForDelete,FindFileData.cFileName);
if ( ! ::DeleteFileW(serverPath1_ForDelete) )
{
dwError = ::GetLastError();
::MessageBoxW(NULL,L"删除文件发生错误",L"错误",MB_OK|MB_ICONERROR);
}
}
}
dwError = GetLastError();
FindClose(hFind);
if (dwError != ERROR_NO_MORE_FILES)
{
::MessageBoxW(NULL,L"循环查找文件发生错误",L"错误",MB_OK|MB_ICONERROR);
}
return;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-02-08
展开全部
新春到来喜事多,合家团圆幸福多;心情愉快朋友多,身体健康快乐多;一切顺利福气多,新年吉祥生意多;祝您好事多!多!多! 加分吧,嘻嘻
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-02-10
展开全部
为了提倡环保,节省纸张,在春节千万别送我贺卡,请在尽可能大的人民币上写下祝福的话送我就可以了,节约是美德,祝春节快乐!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询