2011-10-25 73 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方法。