2011-01-06 10 views
0

Ich probiere gerade die Boost-Bibliotheken aus und habe einen Fehler gemeldet. einfachBoost-Fehler 'Zuweisung von schreibgeschütztem Ort' und 'keine passende Funktion für Anruf' (Neuinstallation)

ist der Code:

#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; 
} 

Wenn ich es kompilieren bekomme ich einen massiven Block von Text, von denen die beiden folgenden Zeilen denke ich, sind nützlich:

/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*)â 

und

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

Ich habe versucht, ein einfaches Boost-Beispiel von der Boost-Website und das funktioniert, aber trotz viel Gaunerei und s Ich kann nicht herausfinden, warum diese Erase_all Funktion nicht funktioniert. Ich habe das Gefühl, es ist ein fehlender Include, aber ich kann nicht herausfinden, welche.

Kann jemand Licht darauf werfen?

Der vollständige Fehlerausgang ist:

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*&)â 
+1

ich einen idiotischen Fehler gemacht haben. Der Funktionsaufruf sollte wie folgt lauten (astring, ""). Also habe ich die Argumente falsch verstanden. Was für eine Zeitverschwendung. Die Lösung war string thestring = "der schnelle braune Fuchs"; erase_all (thestring, ""); – Columbo

+0

Sie haben auch darum gebeten, etwas zu ändern, das nicht geändert werden kann - ein Literal. – CashCow

+0

Auch sollten Sie Ihre Includes zu #include chris

Antwort

0

Sie haben die Argumente umgesetzt und die Eingabezeichenfolge muss nicht konstanten sein.

Wechsel:

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

zu:

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

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

Neben der Tatsache, dass Sie die Eingaben in boost :: setzen erase_all falsch herum, was Sie versuchen, ist unmöglich zu erreichen.

Beides, was Sie als Parameter eingegeben haben, sind unveränderliche Arrays von Bytes und können nicht durch Boost geändert werden.

sollte diese Arbeit:

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