gpt4 book ai didi

c++ - 使用 boost to_lower & trim 时出现 gcc 链接器错误

转载 作者:太空宇宙 更新时间:2023-11-04 15:54:53 26 4
gpt4 key购买 nike

我尝试在我的代码中使用 boost 库,但在 Sparc Solaris 平台下出现以下链接器错误。

问题代码本质上可以概括为:

#include <boost/algorithm/string.hpp>

std::string xparam;

...
xparam = boost::to_lower(xparam);

链接器错误是:

LdapClient.cc:349: no match for `std::string& = void' operator
/opt/gcc-3.2.3/include/c++/3.2.3/bits/basic_string.h:338: candidates are: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
/opt/gcc-3.2.3/include/c++/3.2.3/bits/basic_string.h:341: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const _CharT*) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
/opt/gcc-3.2.3/include/c++/3.2.3/bits/basic_string.h:344: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
gmake: *** [LdapClient.o] Error 1

有什么想法吗?

最佳答案

boost::to_lower不返回字符串的拷贝,它对传递给函数的变量进行操作。对于某些示例,read this .

所以不需要重新分配:

boost::to_lower(xparam);

你会得到一个错误,因为你试图将字符串分配给值 void

如果你想复制它,使用复制版本:

std::string xparamLowered = boost::to_lower_copy(xparam);

关于c++ - 使用 boost to_lower & trim 时出现 gcc 链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1175823/

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