2011-08-05 20 views
2

我希望在打印我的options_description時允許選項的描述之前打印文本。喜歡的東西:boost :: program_options:如何添加程序描述文本

This program counts from 1 to 10. <--- this is what is missing 

Generic options: 
-h [ --help ]   Produce help message. 
-v [ --version ]  Show program name/version banner and exit. 

目前我的手添加:

if (vm.count("help")) { 
    cout << "options_description\n\n" << my_options_description << endl; 
    return 1; 
} 

是否有可能直接在options_description對象存儲呢?

回答

6

options_description類是用於描述選項,而不是程序。 Program_options庫並非真正用於通用文檔。

我想你可能濫用標籤:

po::options_description options(
    "This program counts from 1 to 10.\n\nGeneric options"); 
+0

似乎將符合該法案,但你會碰到的問題用[多個選項的說明](當http://www.boost.org /doc/libs/1_48_0/doc/html/program_options/howto.html#id2444931)。但是,不過,+1。 – rcollyer

+0

稍微簡單一點就是'if(vm.count(「help」))'在寫入選項之前打印包含格式化用法+概要的單獨字符串。 – TemplateRex

+0

這就是問題中已經顯示的@Template。正如你所說,我不確定那是「容易」的;看起來大致相同的工作量。 –