gpt4 book ai didi

c++ - TCLAP 问题与解析 std::wstring

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:58:36 26 4
gpt4 key购买 nike

TCLAP std::wstring 问题。大家好,

我正在使用 TCLAP(命令行解析实用程序)。到目前为止它一直运行良好,直到我遇到 wstring 处理能力的问题。

我有以下行来解析 UnlabeledValueArg 的代码

std::wstring defaultValue; 

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

我遇到了编译时问题(Visual Studio 吐出了大量令人难以置信的问题。)。我的问题是有没有人尝试过将 std::wstring 与 TCLAP 一起使用。如果是,您可以发布解决方案或解决方法。谢谢。

编辑 - 我收到的编译器警告是 -

C:\DevProjects\MyProjects\nttoolkit\trunk\external\tclap/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.0\VC\include\xstring(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.0\VC\include\xstring(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.0\VC\include\xstring(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:\DevProjects\MyProjects\nttoolkit\trunk\external\tclap/Arg.h(446)

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

    C:\DevProjects\MyProjects\nttoolkit\trunk\external\tclap/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:\DevProjects\MyProjects\nttoolkit\trunk\external\tclap/ValueArg.h(389)

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

    C:\DevProjects\MyProjects\nttoolkit\trunk\external\tclap/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:\DevProjects\MyProjects\nttoolkit\trunk\external\tclap/UnlabeledValueArg.h(44)

: see reference to class template

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

    C:\DevProjects\MyProjects\nttoolkit\trunk\tasksecure\src\main.cpp(26)

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

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

最佳答案

我下载了源代码并构建了您的示例。 UnlabeledValueArg 确实采用 std::string,所以很抱歉。 StandardTraits.h:202 显示 dst = src。它试图将 std::string 设置为 std::wstring 并且没有转换。显然,TCLAP 不支持 std::wstring。 src 应该是 std::wstring。

一种变通方法可能是改用 std::string,并在使用 TCLAP 之前使用 UTF-8 对程序的参数进行编码。

另一种选择是要求 TCLAP 的所有者扩展它以支持广义和狭义论点。

关于c++ - TCLAP 问题与解析 std::wstring,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5980212/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com