c++ - 如何在ROS环境下用POCO库写XML

标签 c++ xml ros poco-libraries

我想创建使用 POCO 库读写 xml 的 C++ 程序。

所以,我写了一个简单的程序。

我可以读取每个 xml 元素。

但我无法编写新的 xml 元素。

下面是test.xml。

<config>
    <prop1>value1</prop1>
</config>

这是我的代码。

#include <iostream>
#include <string>
#include <Poco/AutoPtr.h>
#include <Poco/Util/XMLConfiguration.h>

using Poco::AutoPtr;
using Poco::Util::XMLConfiguration;

int main(int argc, char const* argv[])
{
    AutoPtr<XMLConfiguration> pConf(new XMLConfiguration("test.xml"));

    std::string prop1 = pConf->getString("prop1");
    std::cout << "prop1 =  " << prop1 << std::endl;

    pConf->setString("prop2", "input");
    pConf->save("test.xml");

    return 0;
}

程序运行后,我希望 xml 文件更改如下。

<config>
    <prop1>value1</prop1>
    <prop2>input</prop2> <--New element added!!
</config>

但是结果如下。

<config>
    <prop1>value1</prop1>
</config>

没有任何改变...

我做错了什么?

提前致谢。

添加信息如下

  • 操作系统::Linux Mint18.1
  • POCO 库版本::1.7.6(从源代码构建)
  • 构建系统::CMake、make 和 GCC

我运行以下命令。

sudo apt-get remove ros-kinetic-desktop-full

然后,我可以使用上面的程序编写 xml 文件。

我认为 ros 使用 POCO 库,它与我的 POCO 库重复。

所以我尝试将 POCO library(ros) 替换为 POCO library(mine)。

我的尝试很顺利!

最佳答案


解决方法如下

如果你可以读取 xml 文件而不能使用 POCO 库编写 xml 文件。

您的 POCO 库和 ROS 的 POCO 库可能重复。

尝试以下命令。

  1. 安装ROS

    sudo apt-get install ros-kinetic-desktop-full

  2. 将带有目标前缀 的 Poco 库重新安装到/usr/lib 和/usr/include

    ./configure --prefix=/usr

    制作

    sudo 进行安装

关于c++ - 如何在ROS环境下用POCO库写XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42561010/

相关文章:

C++将wchar_t反斜杠插入字符串

c++ - 将子部件上的 Qt 鼠标(拖动)事件传递给父部件

xml - 是否有更快的方法来检查 LINQ to XML 中的 XML 元素并解析 bool?

android - XML 驱动的 GUI 和性能

Android 相机图像实时传输到 ROS 有 OOM 问题吗?

c++ - 为什么 stringstream 会产生奇怪的值?

c++ - 如何获得非常精确的耗时 C++

python - 如何在一个多对一字段中连接多个字符字段?

python - 在 Ubuntu 14.04 (Beaglebone Black) 上使用带有 ROS 的 python Adafruit_BBIO GPIO 时出错

c++ - 如何在ros中使用Qt库