gpt4 book ai didi

c++ - Boost 错误 'assignment of read-only location' 和 'no matching function for call'(新安装)

转载 作者:行者123 更新时间:2023-11-28 08:24:16 28 4
gpt4 key购买 nike

我刚刚试用了 Boost 库,但遇到了错误。

代码很简单:

#include <string>
#include <iostream>
#include "/usr/include/boost/algorithm/string.hpp";
#include "/usr/include/boost/algorithm/string/erase.hpp";

using namespace std;
using namespace boost;
using namespace boost::algorithm;
using namespace boost::string;


int main()
{
erase_all(" ","the quick brown fox");
return 1;
}

当我编译它时,我得到了一大段文本,其中我认为以下两行很有用:

/usr/include/boost/algorithm/string/detail/find_format_all.hpp:249: error: no matching function for call to âerase(const char [2], const char*&, const char*)â

/usr/include/boost/algorithm/string/detail/replace_storage.hpp:98: error: assignment of read-only location

我已经尝试了 Boost 网站上的一个简单的 Boost 示例并且它有效,但是尽管进行了大量的摆弄和搜索,我还是无法弄清楚为什么这个 erase_all 函数不起作用。我有一种感觉,它缺少一个包含,但我不知道是哪个。

任何人都可以阐明这一点吗?

完整的错误输出是:

test1.cpp:3:51: warning: extra tokens at end of #include directive
/usr/include/boost/algorithm/string/detail/find_format_all.hpp: In function âvoid boost::algorithm::detail::find_format_all_impl2(InputT&, FinderT, FormatterT, FindResultT, FormatResultT) [with InputT = const char [2], FinderT = boost::algorithm::detail::first_finderF<const char*, boost::algorithm::is_equal>, FormatterT = boost::algorithm::detail::empty_formatF<char>, FindResultT = boost::iterator_range<const char*>, FormatResultT = boost::algorithm::detail::empty_container<char>]â:
/usr/include/boost/algorithm/string/detail/find_format_all.hpp:179: instantiated from âvoid boost::algorithm::detail::find_format_all_impl(InputT&, FinderT, FormatterT, FindResultT) [with InputT = const char [2], FinderT = boost::algorithm::detail::first_finderF<const char*, boost::algorithm::is_equal>, FormatterT = boost::algorithm::detail::empty_formatF<char>, FindResultT = boost::iterator_range<const char*>]â
/usr/include/boost/algorithm/string/find_format.hpp:247: instantiated from âvoid boost::algorithm::find_format_all(SequenceT&, FinderT, FormatterT) [with SequenceT = const char [2], FinderT = boost::algorithm::detail::first_finderF<const char*, boost::algorithm::is_equal>, FormatterT = boost::algorithm::detail::empty_formatF<char>]â
/usr/include/boost/algorithm/string/erase.hpp:588: instantiated from âvoid boost::algorithm::erase_all(SequenceT&, const RangeT&) [with SequenceT = const char [2], RangeT = char [20]]â
test1.cpp:12: instantiated from here
/usr/include/boost/algorithm/string/detail/find_format_all.hpp:249: error: no matching function for call to âerase(const char [2], const char*&, const char*)â
/usr/include/boost/algorithm/string/detail/find_format_all.hpp:179: instantiated from âvoid boost::algorithm::detail::find_format_all_impl(InputT&, FinderT, FormatterT, FindResultT) [with InputT = const char [2], FinderT = boost::algorithm::detail::first_finderF<const char*, boost::algorithm::is_equal>, FormatterT = boost::algorithm::detail::empty_formatF<char>, FindResultT = boost::iterator_range<const char*>]â
/usr/include/boost/algorithm/string/find_format.hpp:247: instantiated from âvoid boost::algorithm::find_format_all(SequenceT&, FinderT, FormatterT) [with SequenceT = const char [2], FinderT = boost::algorithm::detail::first_finderF<const char*, boost::algorithm::is_equal>, FormatterT = boost::algorithm::detail::empty_formatF<char>]â
/usr/include/boost/algorithm/string/erase.hpp:588: instantiated from âvoid boost::algorithm::erase_all(SequenceT&, const RangeT&) [with SequenceT = const char [2], RangeT = char [20]]â
test1.cpp:12: instantiated from here
/usr/include/boost/algorithm/string/detail/find_format_all.hpp:254: error: no matching function for call to âinsert(const char [2], const char*, std::_Deque_iterator<char, char&, char*>, std::_Deque_iterator<char, char&, char*>)â
/usr/include/boost/algorithm/string/detail/replace_storage.hpp: In member function âForwardIteratorT boost::algorithm::detail::process_segment_helper<HasStableIterators>::operator()(StorageT&, InputT&, ForwardIteratorT, ForwardIteratorT, ForwardIteratorT) [with StorageT = std::deque<char, std::allocator<char> >, InputT = const char [2], ForwardIteratorT = const char*, bool HasStableIterators = false]â:
/usr/include/boost/algorithm/string/detail/replace_storage.hpp:150: instantiated from âForwardIteratorT boost::algorithm::detail::process_segment(StorageT&, InputT&, ForwardIteratorT, ForwardIteratorT, ForwardIteratorT) [with StorageT = std::deque<char, std::allocator<char> >, InputT = const char [2], ForwardIteratorT = const char*]â
/usr/include/boost/algorithm/string/detail/find_format_all.hpp:221: instantiated from âvoid boost::algorithm::detail::find_format_all_impl2(InputT&, FinderT, FormatterT, FindResultT, FormatResultT) [with InputT = const char [2], FinderT = boost::algorithm::detail::first_finderF<const char*, boost::algorithm::is_equal>, FormatterT = boost::algorithm::detail::empty_formatF<char>, FindResultT = boost::iterator_range<const char*>, FormatResultT = boost::algorithm::detail::empty_container<char>]â
/usr/include/boost/algorithm/string/detail/find_format_all.hpp:179: instantiated from âvoid boost::algorithm::detail::find_format_all_impl(InputT&, FinderT, FormatterT, FindResultT) [with InputT = const char [2], FinderT = boost::algorithm::detail::first_finderF<const char*, boost::algorithm::is_equal>, FormatterT = boost::algorithm::detail::empty_formatF<char>, FindResultT = boost::iterator_range<const char*>]â
/usr/include/boost/algorithm/string/find_format.hpp:247: instantiated from âvoid boost::algorithm::find_format_all(SequenceT&, FinderT, FormatterT) [with SequenceT = const char [2], FinderT = boost::algorithm::detail::first_finderF<const char*, boost::algorithm::is_equal>, FormatterT = boost::algorithm::detail::empty_formatF<char>]â
/usr/include/boost/algorithm/string/erase.hpp:588: instantiated from âvoid boost::algorithm::erase_all(SequenceT&, const RangeT&) [with SequenceT = const char [2], RangeT = char [20]]â
test1.cpp:12: instantiated from here
/usr/include/boost/algorithm/string/detail/replace_storage.hpp:98: error: assignment of read-only location
/usr/include/boost/algorithm/string/detail/replace_storage.hpp: In function âOutputIteratorT boost::algorithm::detail::move_from_storage(StorageT&, OutputIteratorT, OutputIteratorT) [with StorageT = std::deque<char, std::allocator<char> >, OutputIteratorT = const char*]â:
/usr/include/boost/algorithm/string/detail/replace_storage.hpp:70: instantiated from âForwardIteratorT boost::algorithm::detail::process_segment_helper<HasStableIterators>::operator()(StorageT&, InputT&, ForwardIteratorT, ForwardIteratorT, ForwardIteratorT) [with StorageT = std::deque<char, std::allocator<char> >, InputT = const char [2], ForwardIteratorT = const char*, bool HasStableIterators = false]â
/usr/include/boost/algorithm/string/detail/replace_storage.hpp:150: instantiated from âForwardIteratorT boost::algorithm::detail::process_segment(StorageT&, InputT&, ForwardIteratorT, ForwardIteratorT, ForwardIteratorT) [with StorageT = std::deque<char, std::allocator<char> >, InputT = const char [2], ForwardIteratorT = const char*]â
/usr/include/boost/algorithm/string/detail/find_format_all.hpp:221: instantiated from âvoid boost::algorithm::detail::find_format_all_impl2(InputT&, FinderT, FormatterT, FindResultT, FormatResultT) [with InputT = const char [2], FinderT = boost::algorithm::detail::first_finderF<const char*, boost::algorithm::is_equal>, FormatterT = boost::algorithm::detail::empty_formatF<char>, FindResultT = boost::iterator_range<const char*>, FormatResultT = boost::algorithm::detail::empty_container<char>]â
/usr/include/boost/algorithm/string/detail/find_format_all.hpp:179: instantiated from âvoid boost::algorithm::detail::find_format_all_impl(InputT&, FinderT, FormatterT, FindResultT) [with InputT = const char [2], FinderT = boost::algorithm::detail::first_finderF<const char*, boost::algorithm::is_equal>, FormatterT = boost::algorithm::detail::empty_formatF<char>, FindResultT = boost::iterator_range<const char*>]â
/usr/include/boost/algorithm/string/find_format.hpp:247: instantiated from âvoid boost::algorithm::find_format_all(SequenceT&, FinderT, FormatterT) [with SequenceT = const char [2], FinderT = boost::algorithm::detail::first_finderF<const char*, boost::algorithm::is_equal>, FormatterT = boost::algorithm::detail::empty_formatF<char>]â
/usr/include/boost/algorithm/string/erase.hpp:588: instantiated from âvoid boost::algorithm::erase_all(SequenceT&, const RangeT&) [with SequenceT = const char [2], RangeT = char [20]]â
test1.cpp:12: instantiated from here
/usr/include/boost/algorithm/string/detail/replace_storage.hpp:35: error: assignment of read-only location
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algobase.h: In function â_OI std::__copy_aux(_II, _II, _OI) [with _II = const char*, _OI = const char*]â:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algobase.h:326: instantiated from âstatic _OI std::__copy_normal<<anonymous>, <anonymous> >::copy_n(_II, _II, _OI) [with _II = const char*, _OI = const char*, bool <anonymous> = false, bool <anonymous> = false]â
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algobase.h:387: instantiated from â_OutputIterator std::copy(_InputIterator, _InputIterator, _OutputIterator) [with _InputIterator = const char*, _OutputIterator = const char*]â
/usr/include/boost/algorithm/string/detail/replace_storage.hpp:87: instantiated from âForwardIteratorT boost::algorithm::detail::process_segment_helper<HasStableIterators>::operator()(StorageT&, InputT&, ForwardIteratorT, ForwardIteratorT, ForwardIteratorT) [with StorageT = std::deque<char, std::allocator<char> >, InputT = const char [2], ForwardIteratorT = const char*, bool HasStableIterators = false]â
/usr/include/boost/algorithm/string/detail/replace_storage.hpp:150: instantiated from âForwardIteratorT boost::algorithm::detail::process_segment(StorageT&, InputT&, ForwardIteratorT, ForwardIteratorT, ForwardIteratorT) [with StorageT = std::deque<char, std::allocator<char> >, InputT = const char [2], ForwardIteratorT = const char*]â
/usr/include/boost/algorithm/string/detail/find_format_all.hpp:221: instantiated from âvoid boost::algorithm::detail::find_format_all_impl2(InputT&, FinderT, FormatterT, FindResultT, FormatResultT) [with InputT = const char [2], FinderT = boost::algorithm::detail::first_finderF<const char*, boost::algorithm::is_equal>, FormatterT = boost::algorithm::detail::empty_formatF<char>, FindResultT = boost::iterator_range<const char*>, FormatResultT = boost::algorithm::detail::empty_container<char>]â
/usr/include/boost/algorithm/string/detail/find_format_all.hpp:179: instantiated from âvoid boost::algorithm::detail::find_format_all_impl(InputT&, FinderT, FormatterT, FindResultT) [with InputT = const char [2], FinderT = boost::algorithm::detail::first_finderF<const char*, boost::algorithm::is_equal>, FormatterT = boost::algorithm::detail::empty_formatF<char>, FindResultT = boost::iterator_range<const char*>]â
/usr/include/boost/algorithm/string/find_format.hpp:247: instantiated from âvoid boost::algorithm::find_format_all(SequenceT&, FinderT, FormatterT) [with SequenceT = const char [2], FinderT = boost::algorithm::detail::first_finderF<const char*, boost::algorithm::is_equal>, FormatterT = boost::algorithm::detail::empty_formatF<char>]â
/usr/include/boost/algorithm/string/erase.hpp:588: instantiated from âvoid boost::algorithm::erase_all(SequenceT&, const RangeT&) [with SequenceT = const char [2], RangeT = char [20]]â
test1.cpp:12: instantiated from here
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_algobase.h:317: error: no matching function for call to âstd::__copy<true, std::random_access_iterator_tag>::copy(const char*&, const char*&, const char*&)â

最佳答案

除了您将输入以错误的方式放入 boost::erase_all 之外,您试图实现的目标也是不可能的。

你输入的两个参数都是不可变的字节数组,不能被 boost 修改。

这应该有效:

std::string input("The quick brown fox");
boost::erase_all(input, " " );
std::cout << input << std::endl; // hopefully prints Thequickbrownfox

关于c++ - Boost 错误 'assignment of read-only location' 和 'no matching function for call'(新安装),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4614436/

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