2011-10-25 116 views
2

我正在使用Boost.program_options庫並需要指定具有Unicode支持的implicit_value。Boost.program_options:implicit_value和Unicode導致編譯時錯誤

對於ANSI字符串此代碼工作正常

po::options_description desc("Usage"); 
desc.add_options() 
    ("help,h", "produce help message") 
    ("-option,o", po::value<std::string>()->implicit_value(""), "descr"); 

但是,如果使用Unicode支持這樣

po::options_description desc("Usage"); 
desc.add_options() 
    ("help,h", "produce help message") 
    ("-option,o", po::wvalue<std::wstring>()->implicit_value(L""), "descr"); 

我收到以下錯誤:

boost/lexical_cast.hpp(1096): error C2039: 'setg' : is not a member of 'boost::detail::lexical_stream_limited_src<CharT,Base,Traits>' 

boost/lexical_cast.hpp(1097): error C2664: 'std::basic_istream<_Elem,_Traits>::basic_istream(std::basic_streambuf<_Elem,_Traits> *,bool)' : cannot convert parameter 1 from 'base *' to 'std::basic_streambuf<_Elem,_Traits> *' 

boost/lexical_cast.hpp(1103): error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::basic_istream<_Elem,_Traits>' (or there is no acceptable conversion) 

我該怎麼做錯了?

+3

請參閱http://stackoverflow.com/questions/6921196/in-boostprogram-options-how-to-set-default-value-for-wstring獲取解釋和修復。 –

+0

Sahab Yazdani,謝謝。 – vkrzv

回答

1

當嘗試使用Unicode支持的default_value方法時,我會得到完全相同的錯誤。但是,在查看Boost源代碼之後,看起來program_options中的Unicode支持不完整(無論是該文件還是使用該文件所必需的文檔)。看來,使用implicit_value和/或default_value方法確實與錯誤無關;而是使用價值與價值。

0

這實際上是boost::lexical_cast< std::string, std::wstring >的錯誤。我剛剛爲此here創建了錯誤票證。現在您可以使用帶2個參數的重載並自己提供文本表示。這也適用於default_value方法。

相關問題