【发布时间】:2026-01-11 18:55:02
【问题描述】:
在 Linux 中我有这样的东西:
boost::property_tree::xml_parser::read_xml(argv[1], pt);
// huge parsing
for (auto const& itemNode : rootNode2.second) {
const pt::ptree& dealAttributes = itemNode.second.get_child("<xmlattr>", empty_ptree());
for (auto const& dealAttr : dealAttributes)
{
const std::string& attrName = dealAttr.first;
const std::string& attrVal = dealAttr.second.data();
- 原始 xml 是 windows-1251。
- attrVal 是俄罗斯文字
- 我需要它与程序中的常量进行比较。
我应该如何定义这个常量?在 Linux 中,默认的俄语编码似乎不是 Windows-1251,所以我的比较失败了。
这是一个示例 xml:
<?xml version="1.0" encoding="cp1251"?>
<root>
<item accounting_currency_code="RUB" board_name="ФБ Т+2"
broker_commission="71.85" broker_ref="3/00/2"
conclusion_date="2013-09-11T00:00:00" conclusion_time="2013-09-11T11:04:35"
deal_no="480" execution_date="2013-09-12T00:00:00" price="144.700000"
price_currency_code="RUB" request_no="1976"
security_grn_code="1-02-008-A" security_name="ГАЗПРОМ ао"
sell_qnty="5000.00000000" volume_currency="718500.00"
volume_rur="718500.00"/>
</root>
【问题讨论】:
-
命令 locale -a 将显示您的系统上可用的语言环境,我在 Ubuntu 中对其进行了测试,但我没有 Windows-1251
-
这里有一个解决方案可以在Ubuntu中添加Windows-1251:forum.ubuntu.ru/index.php?topic=220034.0
-
您有示例 XML 吗?所以我们知道你在说什么并且可以测试?
-
@sehe 我不敢给出示例 xml,因为它包含机密信息。一般来说,我需要调整
boost::property_tree::xml_parser以获得正确的编码,并使用相同的编码在我的代码中声明文字。 -
来吧。您可以比我们更容易地获得匿名样本。只是编造一些东西?只要能证明问题...