Hi guys, I am following the book C++ Cookbook from O'Reilly and I try one of the examples, here is the code:
#include <string>
#include <iostream>
#include <cctype>
#include <cwctype>
using namespace std;
template<typename T, typename F>
void rtrimws(basic_string<T>& s, F f){
if(s.empty())
return;
typename basic_string<T>::iterator p;
for(p = s.end(); p != s.begin() && f(*--p););
if(!f(*p))
p++;
s.erase(p, s.end());
}
void rtrimws(string& ws){
rtrimws(ws, isspace);
}
void rtrimws(wstring& ws){
rtrimws(ws, iswspace);
}
int main(){
string s = "zing ";
wstring ws = L"zonh ";
rtrimws(s);
rtrimws(ws);
cout << s << "|\n";
wcout << ws << "|\n";
}
When I try to compile it, I get the following error
trim.cpp: In function ‘void rtrimws(std::string&)’:
trim.cpp:22: error: too many arguments to function ‘void rtrimws(std::string&)’
trim.cpp:23: error: at this point in file
and I don't understand what's wrong. If I don't use the char version (string) but the wchar_t version only, everything runs smooth.
By the way, I am using g++ 4.4.3 in an ubuntu machine 64 bits