POCO - 属性文件配置保存方法始终使用 ":" 作为分隔符进行写入

POCO - PropertyFileConfiguration save method always writes using ":" as delimiter

本文关键字:分隔符 文件 属性 配置 保存 方法 POCO      更新时间:2023-10-16

我们目前正在项目中使用POCO库。我正在使用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);

文件1:的输出

key1: value1

但我预计输出应该是:

key1= value1

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

来自文件:

保存

无效保存(std::ostream&奥斯特)const;

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

数据以<键>:<值>用换行符分隔。

如果真的没有其他选项,您可以将自己的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;
    }
}

所以您只需要将": "替换为"= "