#include <iostream> #include <string> using namespace std; class Nnumber : std::unary_function<char, bool>{ static int k; public: bool operator ()(char ch) { if (isdigit(ch)) return false; if ( ch == ',' || ch == '.') { ++k; if(k < 2) return false; else return true; } return true; } }; int Nnumber::k = 0; void remake(string& s) { s.erase(remove_if(s.begin(), s.end(), Nnumber()), s.end()); } int main(int argc, char *argv[]) { QCoreApplication qca(argc, argv); string s("123, rt45,6j"), s1("567,.. 87"); remake(s); remake(s1); cout << s <<'\n' // "123,457" << s1; // "56787" ??? нет символа ',' return qca.exec(); } I need the string to represent a rational number of arbitrary length, and for this I am trying to exclude any unnecessary character from there. I expected s1 == "567.87", however it is not. I did not understand what the error was. Help please fix
std::unary_functionis deprecated and it is no longer necessary to use it. - AnTstd::unary_functionandstd::binary_functionare no longer at all. - AnT