Poco :: Util::IniFileConfigurationを使用して「.ini」ファイルに変更を加えようとしています。次の例のiniファイルがあります。
[Test]
IP = 192.168.1.1
ファイルに新しいIPを書き込めるようにしたい。私がこれまでに持っているのは:
#include "Poco/Util/IniFileConfiguration.h"
#include <iostream>
int main( int argc, char *argv[] ) {
Poco::AutoPtr<Poco::Util::IniFileConfiguration> pConf( new Poco::Util::IniFileConfiguration( "file.ini" ) );
if ( pConf->has( "Test.IP" ) ) {
try {
std::cout << pConf->getString( "Test.IP" ) << std::endl;
pConf->setString( "Test.IP", "127.0.0.1" );
std::cout << pConf->getString( "Test.IP" ) << std::endl;
// TODO Make changes permanent; write to file!
} catch ( Poco::SyntaxException& e ) {
std::cerr << "writeValue: " << e.displayText() << std::endl;
return -1;
}
}
return 0;
}
このコードは次のように出力します。
192.168.1.1
127.0.0.1
IPは実行時に変更されますが、変更内容はディスクに書き込まれません(file.iniは変更されません)。これを達成する簡単な方法はありますか?
ありがとうございました!