gpt4 book ai didi

c++ - 包含字符串时出现 STL_algobase.h 错误

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

在最近创建的项目中,我在尝试 make 时遇到此错误:

备注:params.h:11只是#include <string>

Building file: ../src/cmds/params.cpp
Invoking: Cross G++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/cmds/params.d" -MT"src/cmds/params.d" -o "src/cmds/params.o" "../src/cmds/params.cpp"
In file included from /usr/include/c++/4.8/bits/char_traits.h:39:0,
from /usr/include/c++/4.8/string:40,
from ../src/cmds/params.h:11,
from ../src/cmds/params.cpp:8:
/usr/include/c++/4.8/bits/stl_algobase.h: In instantiation of ‘static _OI std::__copy_move<false, false, std::random_access_iterator_tag>::__copy_m(_II, _II, _OI) [with _II = char*; _OI = std::ostream_iterator<std::basic_string<char> >]’:
/usr/include/c++/4.8/bits/stl_algobase.h:390:70: required from ‘_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = false; _II = char*; _OI = std::ostream_iterator<std::basic_string<char> >]’
/usr/include/c++/4.8/bits/stl_algobase.h:428:38: required from ‘_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = false; _II = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >; _OI = std::ostream_iterator<std::basic_string<char> >]’
/usr/include/c++/4.8/bits/stl_algobase.h:460:17: required from ‘_OI std::copy(_II, _II, _OI) [with _II = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >; _OI = std::ostream_iterator<std::basic_string<char> >]’
../src/cmds/params.cpp:96:81: required from here
/usr/include/c++/4.8/bits/stl_algobase.h:335:18: error: invalid user-defined conversion from ‘char’ to ‘const std::basic_string<char>&’ [-fpermissive]
*__result = *__first;
^
In file included from /usr/include/c++/4.8/string:53:0,
from ../src/cmds/params.h:11,
from ../src/cmds/params.cpp:8:
/usr/include/c++/4.8/bits/basic_string.tcc:212:5: note: candidate is: std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>] <near match>
basic_string<_CharT, _Traits, _Alloc>::
^
/usr/include/c++/4.8/bits/basic_string.tcc:212:5: note: no known conversion for argument 1 from ‘char’ to ‘const char*’
In file included from /usr/include/c++/4.8/bits/char_traits.h:39:0,
from /usr/include/c++/4.8/string:40,
from ../src/cmds/params.h:11,
from ../src/cmds/params.cpp:8:
/usr/include/c++/4.8/bits/stl_algobase.h:335:18: error: invalid conversion from ‘char’ to ‘const char*’ [-fpermissive]
*__result = *__first;
^
In file included from /usr/include/c++/4.8/string:53:0,
from ../src/cmds/params.h:11,
from ../src/cmds/params.cpp:8:
/usr/include/c++/4.8/bits/basic_string.tcc:212:5: error: initializing argument 1 of ‘std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ [-fpermissive]
basic_string<_CharT, _Traits, _Alloc>::
^
make: *** [src/cmds/params.o] Error 1

可能是什么原因?

最佳答案

下面的错误在这里很重要

    /usr/include/c++/4.8/bits/stl_algobase.h:335:18: 
error: invalid user-defined conversion from ‘char’ to ‘const std::basic_string<char>&’ [-fpermissive]
*__result = *__first;

这表明在您的程序中某处您正在尝试将 char 转换为 std::string不可能。

关于c++ - 包含字符串时出现 STL_algobase.h 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23305567/

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