2

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?

user10101
  • 1,704
  • 2
  • 20
  • 49
  • 3
    See http://stackoverflow.com/questions/6921196/in-boostprogram-options-how-to-set-default-value-for-wstring for an explanation and a fix. – Sahab Yazdani Dec 18 '11 at 03:35

2 Answers2

1

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.

Dave Kelly
  • 11
  • 1
0

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 the default_value method.

Oz.
  • 5,299
  • 2
  • 23
  • 30