如何使用libconfig ++和c ++修改.cfg文件中的值

时间:2014-03-13 03:49:31

标签: c++

我有settings.cfg,其中存储了一些信息。出于学习目的,我将在这里发布非常小的settings.cfg

    application = 
    {
           strings =
           {
                hellostring = "hello";
           }
     };

我可以阅读价值,并将其与短代码,不包含和主

一起变为可变
       libconfig::Config cfg; 
       std::string  helloVariable = cfg.lookup("application.strings.hellostring");
     std::cout << "Lets cout what we loaded from cfg: " << helloVariable;
     // lets modify helloVariable
     helloVariable = "hello world";

      // how to store modified variable into .cfg, not adding, just modifying 
      // within libconfig++ code, without recreating entire .cfg file with fstream
     return 0;

我正在使用libconfig ++ 1.4.9。 信息:我来自手机,因此代码可能会破坏而且格式不合理

0 个答案:

没有答案