2

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;
}

结果是:

“### ###”

如果我删除ã,结果是好的:

“### 不 ###”

服务器的语言环境定义为:

[]$ locale
LANG=pt_PT
LC_CTYPE="pt_PT"
LC_NUMERIC="pt_PT"

哪个是可用的:

[]$ locale -a|grep pt_PT
pt_PT

谢谢你的帮助。

4

1 回答 1

0

当您的程序启动时,默认情况下它在“C”语言环境中。这是由 POSIX 标准定义的。您需要调用setlocale(LC_ALL,"")(不要忘记#include <locale.h>),根据系统环境变量设置语言环境。

于 2015-02-12T10:46:46.737 回答