Boost.program_options:implicit_value 和 Unicode 导致编译时错误
我正在使用 Boost.program_options 库,需要指定具有 Unicode 支持的隐式_值。
对于 ansi-string ,此代码工作正常
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)
我做错了什么?
I am using Boost.program_options library and need to specify implicit_value with Unicode support.
For ansi-string this code works fine
po::options_description desc("Usage");
desc.add_options()
("help,h", "produce help message")
("-option,o", po::value<std::string>()->implicit_value(""), "descr");
But if I use Unicode support like this
po::options_description desc("Usage");
desc.add_options()
("help,h", "produce help message")
("-option,o", po::wvalue<std::wstring>()->implicit_value(L""), "descr");
I get the following errors:
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)
What do i do wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当尝试使用具有 Unicode 支持的 default_value 方法时,我遇到了完全相同的错误。然而,在查看 Boost 源代码后,program_options 中的 Unicode 支持似乎不完整(无论是使用它还是使用它所需的文档)。看来使用implicit_value 和/或default_value 方法确实与错误无关;相反,它是 wvalue 与 value 的使用。
I get the exact same errors when trying to use the default_value method with Unicode support. However, after looking over the Boost source code, It appears that the Unicode support in program_options is incomplete (either that or the documentation necessary to use it). It seems that the use of the implicit_value and/or default_value methods really have nothing to do with the errors; rather it is the use of wvalue versus value.
这实际上是
boost::lexical_cast
boost::lexical_cast
的错误。 std::string、std::wstring >
。我刚刚在此处创建了错误票证。现在,您可以使用带有 2 个参数的重载并自行提供文本表示。这也适用于default_value
方法。This is actually an error with
boost::lexical_cast< std::string, std::wstring >
. I just created the error ticket for this here. For now you can use the overload that takes 2 parameters and provide the textual representation yourself. This also applies to thedefault_value
method.