TCLAP issus with parsing std::wstring

TCLAP std::wstring issue. Hello All,

I am using TCLAP(command line parsing utility). It has worked well so far until I ran into issues with wstring processing capability.

I have the below line to parse code for an UnlabeledValueArg

std::wstring defaultValue; 

UnlabeledValueArg<std::wstring>
serverName("COMPUTERNAME", "List all scheduled tasks of computer", false,
           defaultValue, "string" );

I run into compile time issues ( Visual Studio spits out incredulous amounts of issues.). My question is have anyone tried using std::wstring with TCLAP. If yes can you post the solution or the approach to it. Thanks.

Edit - The compiler warnings I get is -

C:DevProjectsMyProjectsnttoolkittrunkexternaltclap/StandardTraits.h(187) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'const std::string' (or there is no acceptable conversion)

    c:Program Files (x86)Microsoft Visual Studio

9.0VCincludexstring(914): could be 'std::basic_string<_Elem,_Traits,_Ax>

&std::basic_string<_Elem,_Traits,_Ax>::operator

=(const std::basic_string<_Elem,_Traits,_Ax> &)' with [ _Elem=wchar_t, _Traits=std::char_traits, _Ax=std::allocator ]

    c:Program Files (x86)Microsoft Visual Studio

9.0VCincludexstring(919): or 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(const _Elem *)' with [ _Elem=wchar_t, _Traits=std::char_traits, _Ax=std::allocator ]

    c:Program Files (x86)Microsoft Visual Studio

9.0VCincludexstring(924): or 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::operator =(_Elem)' with [ _Elem=wchar_t, _Traits=std::char_traits, _Ax=std::allocator ] while trying to match the argument list '(std::wstring, const std::string)'

    C:DevProjectsMyProjectsnttoolkittrunkexternaltclap/Arg.h(446)

: see reference to function template instantiation 'void TCLAP::SetString(T &,const std::string &)' being compiled with [ T=std::wstring ]

    C:DevProjectsMyProjectsnttoolkittrunkexternaltclap/ValueArg.h(391)

: see reference to function template instantiation 'void TCLAP::ExtractValue(T &,const std::string &,TCLAP::StringLike)' being compiled with [ T=std::wstring ]

    C:DevProjectsMyProjectsnttoolkittrunkexternaltclap/ValueArg.h(389)

: while compiling class template member function 'void TCLAP::ValueArg::_extractValue(const std::string &)' with [ T=std::wstring ]

    C:DevProjectsMyProjectsnttoolkittrunkexternaltclap/ValueArg.h(325)

: while compiling class template member function 'bool TCLAP::ValueArg::processArg(int *,std::vector<_Ty> &)' with [ T=std::wstring, _Ty=std::string ]

    C:DevProjectsMyProjectsnttoolkittrunkexternaltclap/UnlabeledValueArg.h(44)

: see reference to class template

instantiation 'TCLAP::ValueArg' being compiled with [ T=std::wstring ]

    C:DevProjectsMyProjectsnttoolkittrunktasksecuresrcmain.cpp(26)

: see reference to class template instantiation 'TCLAP::UnlabeledValueArg' being compiled with [ T=std::wstring ]

TaskSecure - 1 error(s), 6 warning(s)


I downloaded the source and built your example. The UnlabeledValueArg does take std::string, so apologies. The StandardTraits.h:202 shows dst = src. It is trying to set std::string to a std::wstring and there is no conversion. Apparently, TCLAP does not support std::wstring. The src should be std::wstring.

One work around might be to use std::string instead, and UTF-8 encode your program's arguments before using TCLAP.

Another option is to ask the owner of TCLAP to extend it to support either wide and narrow arguments.

链接地址: http://www.djcxy.com/p/68424.html

上一篇: 隐藏错误C2664

下一篇: TCLAP issus解析std :: wstring