Code:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<string> remove_contents(const string& contents, const string& start_t, const string& end_t)
{
vector<string> ret;
typedef string::const_iterator iter;
iter start = contents.begin();
while(start != contents.end())
{
iter start = find_if(start, contents.end(), equal(start, contents.end(), start_t)) + 8;
iter end = find_if(start, contents.end(), equal(start, contents.end(), end_t)) - 1;
if(start != contents.end())
ret.push_back(string(start, end));
start = end;
}
return ret;
}
int main()
{
string contents("This is a test. I will extract <Title> the contents from between </Title> the title labels.");
string start_t = "<Title>";
string end_t = "</Title>";
vector<string> extract = remove_contents(contents, start_t, end_t);
vector<string>::const_iterator i = extract.begin();
for(i; i < extract.end(); i++)
cout << *i << endl;
return 0;
}
I can't figure out what is causing this error.
Code:
In file included from /usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_algobase.h:67,
from /usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/bits/char_traits.h:41,
from /usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/ios:41,
from /usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/ostream:40,
from /usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/iostream:40,
from split_string1.cpp:1:
/usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_iterator_base_types.h: In instantiation of ‘std::iterator_traits<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >’:
/usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_algobase.h:825: instantiated from ‘bool std::__equal_aux(_II1, _II1, _II2) [with _II1 = const char*, _II2 = std::basic_string<char, std::char_traits<char>, std::allocator<char> >]’
/usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_algobase.h:964: instantiated from ‘bool std::equal(_II1, _II1, _II2) [with _II1 = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _II2 = std::basic_string<char, std::char_traits<char>, std::allocator<char> >]’
split_string1.cpp:15: instantiated from here
/usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_iterator_base_types.h:127: error: no type named ‘iterator_category’ in ‘struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >’
In file included from /usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/algorithm:62,
from split_string1.cpp:4:
/usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_algo.h: In function ‘_RandomAccessIterator std::__find_if(_RandomAccessIterator, _RandomAccessIterator, _Predicate, std::random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Predicate = bool]’:
/usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_algo.h:4248: instantiated from ‘_IIter std::find_if(_IIter, _IIter, _Predicate) [with _IIter = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Predicate = bool]’
split_string1.cpp:15: instantiated from here
/usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_algo.h:222: error: ‘__pred’ cannot be used as a function
/usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_algo.h:4248: instantiated from ‘_IIter std::find_if(_IIter, _IIter, _Predicate) [with _IIter = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Predicate = bool]’
split_string1.cpp:15: instantiated from here
/usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_algo.h:226: error: ‘__pred’ cannot be used as a function
/usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_algo.h:230: error: ‘__pred’ cannot be used as a function
/usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_algo.h:234: error: ‘__pred’ cannot be used as a function
/usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_algo.h:242: error: ‘__pred’ cannot be used as a function
/usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_algo.h:246: error: ‘__pred’ cannot be used as a function
/usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_algo.h:250: error: ‘__pred’ cannot be used as a function
In file included from /usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/bits/char_traits.h:41,
from /usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/ios:41,
from /usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/ostream:40,
from /usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/iostream:40,
from split_string1.cpp:1:
/usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_algobase.h: In static member function ‘static bool std::__equal<_BoolType>::equal(_II1, _II1, _II2) [with _II1 = const char*, _II2 = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool _BoolType = false]’:
/usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_algobase.h:831: instantiated from ‘bool std::__equal_aux(_II1, _II1, _II2) [with _II1 = const char*, _II2 = std::basic_string<char, std::char_traits<char>, std::allocator<char> >]’
/usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_algobase.h:964: instantiated from ‘bool std::equal(_II1, _II1, _II2) [with _II1 = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _II2 = std::basic_string<char, std::char_traits<char>, std::allocator<char> >]’
split_string1.cpp:15: instantiated from here
/usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_algobase.h:801: error: no match for ‘operator++’ in ‘++__first2’
/usr/lib/gcc/i586-redhat-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_algobase.h:802: error: no match for ‘operator*’ in ‘*__first2’
Also, does anybody know how to get rid of all the junk in the error exept for: