我们目前正在项目中使用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
答案 0 :(得分:1)
不是我知道的。班级PropertyFileConfiguration
可以加载<key> = <pair>
和<key> : <pair>
两种格式,但只能使用<key> : <pair>
格式进行保存。
保存强>
无效保存( 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;
}
}
因此,您只需将": "
替换为"= "
。