I'm really confused right now about this compiling issue with my code for the C++ style strings tutorial (took a break from programming and came back, so I haven't advanced much).
Code:#include <iostream> #include <string> using namespace std; int main() { string review; string::size_type length; length = review.length(); int bad; int timesofword; for (bad = review.rfind("bad", review.end()); bad != string::npos; bad = review.rfind("bad", bad)) { timesofword++; bad++; cout<<timesofword<<endl; cin.get(); } }
Results:
13 C:\Documents and Settings\Main\My Documents\stringnpos and find.cpp no matching function for call to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::rfind(const char[4], __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >)'
I don't know at all how to fix it, and I've looked up a bunch of stuff on size_type (I think that's the problem), but still just cannot seem to figure this one out. Could anyone here please help me out and explain to me what I've done incorrectly?