Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C(或C+;+;)的属性文件库 >标题很自我解释:有人知道C++的一个(好)属性文件阅读器库吗?或者,如果没有,C++?_C++_C_Properties - Fatal编程技术网

C(或C+;+;)的属性文件库 >标题很自我解释:有人知道C++的一个(好)属性文件阅读器库吗?或者,如果没有,C++?

C(或C+;+;)的属性文件库 >标题很自我解释:有人知道C++的一个(好)属性文件阅读器库吗?或者,如果没有,C++?,c++,c,properties,C++,C,Properties,编辑:具体地说,我想要一个处理Java中使用的.properties文件格式的库:我猜“properties file”是指配置文件 在这种情况下,谷歌给出了(对C配置文件库的前4次点击): 包含一个平台stl::properties\u文件类。它可用于从文件中读取: using platformstl::properties_file; properties_file properties("stuff.properties"); properties_file::value_

编辑:具体地说,我想要一个处理Java中使用的.properties文件格式的库:

我猜“properties file”是指配置文件

在这种情况下,谷歌给出了(对
C配置文件库的前4次点击)

    • 包含一个
      平台stl::properties\u文件
      类。它可用于从文件中读取:

      using platformstl::properties_file;
      
      properties_file  properties("stuff.properties");
      
      properties_file::value_type  value = properties["name"];
      
      或从内存:

      properties_file  properties(
          "name0=value1\n name1 value1 \n name\\ 2 : value\\ 2  ",
          properties_file::contents);
      
      properties_file::value_type  value0 = properties["name0"];
      
      properties_file::value_type  value1 = properties["name1"];
      
      properties_file::value_type  value2 = properties["name 2"];
      
      看起来最新的1.10版本有一系列全面的单元测试,并且他们已经升级了该类,以处理中给出的所有规则和示例

      唯一明显的问题是
      value\u type
      是的一个实例(如中所述),它有点类似于
      std::string
      ,但实际上并不拥有它的内存。他们这样做大概是为了避免不必要的分配,大概是出于性能原因,这是STLSoft设计所珍视的。但这意味着你不能只是写

      std::string  value0 = properties["name0"];
      
      但是,您可以执行以下操作:

      std::string  value0 = properties["name0"].c_str();
      
      这是:

      std::cout << properties["name0"];
      
      std::coutlibmize(C库)也很有用;它已经存在了很久&是灵活的

      • (www.nongnu.org/mizzle/)
      它远远超出了java.util.Properties。尽管如此,它不一定能处理java属性文件格式(这似乎是您的需求)的极端情况

      参见示例:

      • 简单:www.nongnu.org/mize/simple.conf
      • 疯狂:www.nongnu.org/mize/test.conf

      没有C++包装库,虽然我知道,

      POCO也有一个读取属性文件的实现

      从这里复制了一个简单的示例:

      属性文件内容:

      # a comment
      ! another comment
      key1 = value1
      key2: 123
      key3.longValue = this is a very \
      long value
      path = c:\\test.dat
      
      代码示例

      #include <Poco/Util/PropertyFileConfiguration.h>
      using Poco::AutoPtr;
      using Poco::Util::PropertyFileConfiguration;
      AutoPtr<PropertyFileConfiguration> pConf;
      pConf = new PropertyFileConfiguration("test.properties");
      std::string key1 = pConf->getString("key1");
      int value = pConf->getInt("key2");
      std::string longVal = pConf->getString("key3.longValue");
      
      #包括
      使用Poco::AutoPtr;
      使用Poco::Util::PropertyFileConfiguration;
      自动传输pConf;
      pConf=新属性文件配置(“test.properties”);
      std::string key1=pConf->getString(“key1”);
      int value=pConf->getInt(“键2”);
      std::string longVal=pConf->getString(“key3.longValue”);
      
      事实上并非不言自明,“属性文件”是什么?好吧,我想属性文件格式——Java的一种主要形式——在Java世界之外并不广为人知,这部分解释了为什么我找不到它。请看(我没有足够的声誉将此添加到问题中。)我已经为您添加了它-我希望我已经正确地解释了。任何人都可以编辑他们自己的问题。谢谢,这正是我想要的。我去看看。顺便说一句,您的链接[4]已断开