vFieldValue=dw_pR->GetCollect("B05");
strFieldValue=(char *)_bstr_t(vFieldValue);
dwmc=strFieldValue;
fid.Write(hdd1,strlen(hdd1));
fid.Write(dwmc,strlen(dwmc));
fid.Write(hdd3,strlen(hdd3));
在VC中,取oracle数据库中记录内容,其中单位名称为B05字段,取出后保存在dwmc中,用AfxMessageBox(dwmc)可以显示正常,但当 fid.Write(dwmc,strlen(dwmc));后,生成到文件后是乱码.请教高手如何解决.
strFieldValue=(char *)_bstr_t(vFieldValue);
dwmc=strFieldValue;
fid.Write(hdd1,strlen(hdd1));
fid.Write(dwmc,strlen(dwmc));
fid.Write(hdd3,strlen(hdd3));
在VC中,取oracle数据库中记录内容,其中单位名称为B05字段,取出后保存在dwmc中,用AfxMessageBox(dwmc)可以显示正常,但当 fid.Write(dwmc,strlen(dwmc));后,生成到文件后是乱码.请教高手如何解决.
if(!fidin.Open("d://sjcx//tcb.xml",CFile::modeRead))
{
AfxMessageBox("不能打开读入文件,请检查是否已经打开");
return;
}
VC程序从源文件in.txt内读数据,一行一行读,
fidin.ReadString(inss);//inss是CString如果遇到标记则替换:
if(inss=="dwcxrq")
{
inss.Format("%s",dwrq);
}
替换内容为汉字:dwrq为汉字.
然后写到另一个文件内:
fid.Write(inss,strlen(inss));
问题出来了,
生成的文件中,源文件内的汉字显示正常,但是替换的汉字则是乱码,用AfxMessageBox(dwrq)显示一
下显示的也正常.
请高手指点,谢谢.
setlocale(LC_ALL, "chs");
fid.Write(CA2W(inss), strlen(inss) * sizeof(wchar_t));
//
// 微软太猥琐,在工程是默认设置(Unicode编码)时, 如果不setlocale,中文字符就写不进文件....
//
char* old_locale = _strdup( setlocale(LC_CTYPE,NULL) );
setlocale( LC_CTYPE, "chs" );
... 写文件
setlocale( LC_CTYPE, old_locale ); //还原区域设定
free( old_locale );
这个真收费。 我07年就看到它的license里说收费了。 个人免费, 商业收费。
不过他怎么能知道我的软件里用没用CMarkup呢
setlocale( LC_CTYPE, "chs" );
... 写文件
setlocale( LC_CTYPE, old_locale ); //还原区域设定
free( old_locale );