POCO - PropertyFileConfiguration保存方法始终使用“:”作为分隔符进行写入

时间:2015-04-02 10:47:50

标签: c++ poco-libraries

我们目前正在项目中使用POCO Library。我正在使用setstring来设置键和值映射。如果我尝试保存,我希望该文件应以key= value格式保存。但是POCO将其保存为key: value格式。

有没有办法用key=value格式保存文件?

示例:

Poco::AutoPtr<Poco::Util::PropertyFileConfiguration> pConf;
pConf = new poco::Util::PropertyFileConfiguration(file1);
pConf->setString("key1","value1");
pConf->save(file1);

file1的输出:

key1: value1

但我期待输出应该是:

key1= value1

1 个答案:

答案 0 :(得分:1)

不是我知道的。班级PropertyFileConfiguration可以加载<key> = <pair><key> : <pair>两种格式,但只能使用<key> : <pair>格式进行保存。

来自documentation

  

保存

     

无效保存(       std :: ostream&amp; OSTR   )const;

     

将配置数据写入给定的流。

     

数据以&lt; key&gt;:&lt; value&gt; 的形式写成一系列语句,用换行符分隔。

如果没有其他选项,您可以将自己的saveUsingEqual()功能添加到PropertyFileConfiguration。原始save()的代码非常简单:

void PropertyFileConfiguration::save(std::ostream& ostr) const
{
    MapConfiguration::iterator it = begin();
    MapConfiguration::iterator ed = end();
    while (it != ed)
    {
        ostr << it->first << ": " << it->second << "\n";
        ++it;
    }
}

因此,您只需将": "替换为"= "