cxxopts icon indicating copy to clipboard operation
cxxopts copied to clipboard

std::wstring as argument type doesn't work

Open AndyWatterman opened this issue 3 years ago • 3 comments

I use this code:

("r, prefix", "Output file prefix", cxxopts::value<std::wstring>(prefix))

It generates error:

C2679 binary '>>': no operator found which takes a right-hand operand of type 'T' (or there is no acceptable conversion)

In this function:

 template <typename T>
   void stringstream_parser(const std::string& text, T& value)
   {
     std::stringstream in(text);
     in >> value;
     if (!in) {
       throw_or_mimic<argument_incorrect_type>(text);
     }
   }    

I also tried using icu::UnicodeString instead of std::wstring, the same error occurs.

AndyWatterman avatar Jul 24 '21 07:07 AndyWatterman

C++ string handling is a bit of a mess and I'm not sure I want to try to support wstring. Can you show me the example with UnicodeString? Because I do have a Unicode mode so I wonder if that should work.

jarro2783 avatar Oct 09 '21 06:10 jarro2783

In Windows, as far as I as I know, the only way to receive arguments using Unicode charset is by using the wmain entrypoint, which will encode them in UTF-16 with a 2-bytes wchar_t backend. One sane behavior would be to temporarily convert them to utf-8.

ceztko avatar Mar 30 '23 20:03 ceztko

I was wanting to use this library on a Windows C++ app I'm working on and it's wchar_t top-to-bottom. I've ported this library to use wide strings throughout, it seems to be working well.

https://github.com/matttyson/cxxopts/tree/wstring3

I wasn't intending to submit this as a PR as the diff is quite horrific and I'm sure the author wouldn't want to maintain it. nevertheless you might find it useful.

matttyson avatar Jun 03 '23 00:06 matttyson