Xerces代码转换返回空字符串。我认为这与区域设置问题有关,但我被卡住了。
我有一个简单的程序:
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/dom/DOM.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xercesc/framework/MemBufInputSource.hpp>
#include <xercesc/dom/DOMException.hpp>
#include <string>
#include <stdio.h>
XERCES_CPP_NAMESPACE_USE
using namespace std;
int main(int argc, char* argv[])
{
string a = "Não";
try
{
XMLPlatformUtils::Initialize("pt_PT");
} catch(const XMLException& e)
{
fprintf(stdout,"ERROR INITIALIZING\n");
}
XMLCh *auxCh3 = XMLString::transcode(a.c_str());
fprintf(stdout,"### %s ###\n",XMLString::transcode(auxCh3));
XMLString::release(&auxCh3);
XMLPlatformUtils::Terminate();
return 0;
}结果是:
"### ###“
如果我去掉ã,结果是ok:
"### No ###“
服务器的区域设置定义为:
[]$ locale
LANG=pt_PT
LC_CTYPE="pt_PT"
LC_NUMERIC="pt_PT"这是可用的选项之一:
[]$ locale -a|grep pt_PT
pt_PT谢谢你的帮助。
发布于 2015-02-12 18:46:47
当你的程序启动时,默认情况下是在"C“语言环境下。这是由POSIX标准定义的。您需要调用setlocale(LC_ALL,"") (别忘了调用#include <locale.h> ),以便根据系统环境变量设置语言环境。
https://stackoverflow.com/questions/25749417
复制相似问题