提升错误'只读位置的分配'和'没有匹配的呼叫功能'(新安装)

时间:2011-01-06 11:32:57

标签: c++ boost include

我只是尝试了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*&)â

2 个答案:

答案 0 :(得分:1)

除了你将输入放入boost :: erase_all的事实是错误的方式,你想要达到的目标是不可能的。

您作为参数输入的内容都是不可变的字节数组,无法通过boost修改。

这应该有效:

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

答案 1 :(得分:0)

你有转置的参数,输入字符串必须是非const。

变化:

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

为:

int main()
{
    char s[] = "the quick brown fox";

    erase_all(s, " ");
    return 0;
}