program_options and unicode
Greetings. Say I have a situation like this one: po::options_description visible("Visible options"); visible.add_options() ("opt1", "opt1") ("opt2", "opt2") ("opt3", "opt3") ; po::options_description hidden("Hidden options"); hidden.add_options() ("opt4", po::value<string>(), "opt4") ; po::options_description all_options; all_options.add(visible).add(hidden); po::positional_options_description pos; pos.add("opt4", -1); po::variables_map vm; po::store(po::command_line_parser(argc, argv).options(all_options).positional(pos).run(), vm); po::notify(vm); Now I want to replace char* argv[] with wchar_t* in order to pass a Unicode file name to a Win32 SDK function CreateFile(). What would be, in your opinion, an appropriate course of action? I thank you in advance. ZA
zh wrote:
Greetings.
po::options_description hidden("Hidden options"); hidden.add_options() ("opt4", po::value<string>(), "opt4") ; ...... po::variables_map vm; po::store(po::command_line_parser(argc, argv).options(all_options).positional(pos).run(), vm); po::notify(vm);
Now I want to replace char* argv[] with wchar_t* in order to pass a Unicode file name to a Win32 SDK function CreateFile(). What would be, in your opinion, an appropriate course of action? I thank you in advance.
1. Replace char* argv[] with wchar_t *arv[]. (And modify whatever IDE/compiler settings are necessary to enable wchar_t main). 2. Use 'wstring' as the type of your options, not 'string'. Then, everything is supposed to work. - Volodya
Vladimir Prus wrote:
<cut />
Sorry for the delay; I was away from my computer for a couple of days. So, I even tried your solution before you mentioned it (following the online manual for Program Options, I presume) and it didn't work.
1. Replace char* argv[] with wchar_t *arv[]. 2. Use 'wstring' as the type of your options, not 'string'.
The compiler (VC8) casts: error C2665: 'boost::program_options::basic_command_line_parser<charT>::basic_command_line_parser' : none of the 3 overloads could convert all the argument types with [ charT=char ] c:\program files\boost\boost_1_34_0\boost\program_options\parsers.hpp(98): could be 'boost::program_options::basic_command_line_parser<charT>::basic_command_line_parser(int,charT *[])' with [ charT=char ] while trying to match the argument list '(int, wchar_t *[])' Your opinion? TIA!
zh wrote:
Vladimir Prus wrote:
<cut />
Sorry for the delay; I was away from my computer for a couple of days. So, I even tried your solution before you mentioned it (following the online manual for Program Options, I presume) and it didn't work.
1. Replace char* argv[] with wchar_t *arv[]. 2. Use 'wstring' as the type of your options, not 'string'.
You also need to change the string literals: "You have this" L"You should have this" // Note the L in front of the string K
participants (3)
-
Kirit Sælensminde
-
Vladimir Prus
-
zh