首頁 > 程式設計 > [C/C++] Read configuration file

[C/C++] Read configuration file

說來也趣味,這篇文章的起因是因為我在改寫 Apriori code時,由於看不懂其中某段configure_file的操作,就上網找一些資訊。

偶然間發現可以讀取configuration file的小程式:A C++ Class to read Configuration file

例如,他只要寫下列設定檔:
[section_1]
foo = bar
water= h2o

[section_2]
foo = foo
water= wet
four = 4.2
然後在讀取程式那邊這麼寫:

 ConfigFile cf("config.txt");

  std::string foo;
  std::string water;
  double      four;

  foo   = cf.Value("section_1","foo"  );
  water = cf.Value("section_2","water");
  four  = cf.Value("section_2","four" );

  std::cout << foo   << std::endl;
  std::cout << water << std::endl;
  std::cout << four  << std::endl;

就可以輕鬆讀取設定檔了。若想要知道詳細的code,請到A C++ Class to read Configuration file

分類:程式設計 標籤:,
  1. 仍無迴響。
  1. No trackbacks yet.

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

Google+ photo

You are commenting using your Google+ account. Log Out / 變更 )

連結到 %s

%d 位部落客按了讚: