Remove_if Error can someone help?

1
2
3
4
5
 getline (file1,line);
		
		line.erase(
      std::remove_if(line.begin(), line.end(), &isdigit), // removes digits.
		line.end());


Error:
inputappointments.cpp: In function âVector<String> read_file(std::istream&)â:
inputappointments.cpp:54:56: error: no matching function for call to âremove_if(std::basic_string<char>::iterator, std::basic_string<char>::iterator, <unresolved overloaded function type>)â"



I posted Code on 2nd post





All the Error:


The error code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
inputappointments.cpp: In function âVector<String> read_file(std::istream&)                                                                                  â:
inputappointments.cpp:54:56: error: no matching function for call to âremov                                                                                  e_if(std::basic_string<char>::iterator, std::basic_string<char>::iterator,                                                                                   <unresolved overloaded function type>)â
inputappointments.cpp:54:56: note: candidate is:
In file included from /usr/include/c++/4.7/algorithm:63:0,
                 from /usr/include/c++/4.7/regex:38,
                 from std_lib_facilities_3.h:28,
                 from inputappointments.cpp:18:
/usr/include/c++/4.7/bits/stl_algo.h:1160:5: note: template<class _FIter, c                                                                                  lass _Predicate> _FIter std::remove_if(_FIter, _FIter, _Predicate)
/usr/include/c++/4.7/bits/stl_algo.h:1160:5: note:   template argument dedu                                                                                  ction/substitution failed:
inputappointments.cpp:54:56: note:   couldn't deduce template parameter â_P                                                                                  redicateâ
inputappointments.cpp:57:66: error: no matching function for call to âremov                                                                                  e_if(std::basic_string<char>::iterator, std::basic_string<char>::iterator,                                                                                   <unresolved overloaded function type>)â
inputappointments.cpp:57:66: note: candidate is:
In file included from /usr/include/c++/4.7/algorithm:63:0,
                 from /usr/include/c++/4.7/regex:38,
                 from std_lib_facilities_3.h:28,
                 from inputappointments.cpp:18:
/usr/include/c++/4.7/bits/stl_algo.h:1160:5: note: template<class _FIter, c                                                                                  lass _Predicate> _FIter std::remove_if(_FIter, _FIter, _Predicate)
/usr/include/c++/4.7/bits/stl_algo.h:1160:5: note:   template argument dedu                                                                                  ction/substitution failed:
inputappointments.cpp:57:66: note:   couldn't deduce template parameter â_P                                                                                  redicateâ
inputappointments.cpp: In function âVector<int> read_file1(std::istream&)â:
inputappointments.cpp:82:22: error: no matching function for call to âgetli                                                                                  ne(std::istream&, int&)â
inputappointments.cpp:82:22: note: candidates are:
In file included from /usr/include/c++/4.7/cstdio:44:0,
                 from /usr/include/c++/4.7/ext/string_conversions.h:39,
                 from /usr/include/c++/4.7/bits/basic_string.h:2814,
                 from /usr/include/c++/4.7/string:54,
                 from /usr/include/c++/4.7/stdexcept:40,
                 from /usr/include/c++/4.7/array:39,
                 from std_lib_facilities_3.h:27,
                 from inputappointments.cpp:18:
/usr/include/stdio.h:675:20: note: __ssize_t getline(char**, size_t*, FILE*                                                                                  )
/usr/include/stdio.h:675:20: note:   candidate expects 3 arguments, 2 provi                                                                                  ded
In file included from /usr/include/c++/4.7/string:54:0,
                 from /usr/include/c++/4.7/stdexcept:40,
                 from /usr/include/c++/4.7/array:39,
                 from std_lib_facilities_3.h:27,
                 from inputappointments.cpp:18:
/usr/include/c++/4.7/bits/basic_string.h:2792:5: note: template<class _Char                                                                                  T, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::g                                                                                  etline(std::basic_istream<_CharT, _Traits>&, std::basic_string<_CharT, _Tra                                                                                  its, _Alloc>&)
/usr/include/c++/4.7/bits/basic_string.h:2792:5: note:   template argument                                                                                   deduction/substitution failed:
inputappointments.cpp:82:22: note:   mismatched types âstd::basic_string<_C                                                                                  harT, _Traits, _Alloc>â and âintâ
In file included from /usr/include/c++/4.7/string:55:0,
                 from /usr/include/c++/4.7/stdexcept:40,
                 from /usr/include/c++/4.7/array:39,
                 from std_lib_facilities_3.h:27,
                 from inputappointments.cpp:18:
/usr/include/c++/4.7/bits/basic_string.tcc:1070:5: note: template<class _Ch                                                                                  arT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std:                                                                                  :getline(std::basic_istream<_CharT, _Traits>&, std::basic_string<_CharT, _T                                                                                  raits, _Alloc>&, _CharT)
/usr/include/c++/4.7/bits/basic_string.tcc:1070:5: note:   template argumen                                                                                  t deduction/substitution failed:
inputappointments.cpp:82:22: note:   mismatched types âstd::basic_string<_C                                                                                  harT, _Traits, _Alloc>â and âintâ
inputappointments.cpp:84:8: error: request for member âeraseâ in âlineâ, wh                                                                                  ich is of non-class type âintâ
inputappointments.cpp:85:27: error: request for member âbeginâ in âlineâ, w                                                                                  hich is of non-class type âintâ
inputappointments.cpp:85:41: error: request for member âendâ in âlineâ, whi                                                                                  ch is of non-class type âintâ
inputappointments.cpp:86:8: error: request for member âendâ in âlineâ, whic                                                                                  h is of non-class type âintâ
inputappointments.cpp:88:10: error: request for member âeraseâ in âlineâ, w                                                                                  hich is of non-class type âintâ
inputappointments.cpp:88:37: error: request for member âbeginâ in âlineâ, w                                                                                  hich is of non-class type âintâ
inputappointments.cpp:88:51: error: request for member âendâ in âlineâ, whi                                                                                  ch is of non-class type âintâ
inputappointments.cpp:89:8: error: request for member âendâ in âlineâ, whic                                                                                  h is of non-class type âintâ
inputappointments.cpp: At global scope:
inputappointments.cpp:103:1: error: expected unqualified-id before â{â toke                                                                                  n
Last edited on
My code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
	
#include "std_lib_facilities_3.h"	
#include <iostream>
#include <vector>
#include <fstream>
#include <iterator>
#include <algorithm> 
   
   bool isdigit( char c ) {
    return isdigit( c );
}	 
 bool ispunct( char c ) {
    return ispunct( c );
} 
 bool isalpha( char c ) {
    return isalpha( c );
}

vector<string> read_file(istream& file1)
{
 /*ifstream ist(file1.c_str());                            // error with this c_str
	if (!ist)
	{
		error ("Can't open the input file ", file1);
	}*/

	vector<string> appointments1;              // we gonna use this  vector to store appointment names
	string line;
	//if (file1.is_open())
	//{
	
	  while ( file1.good() )                             //  assuming file1 is the input file
	  {
	
		getline (file1,line);
		
		line.erase(
      std::remove_if(line.begin(), line.end(), &isdigit), // removes digits.
		line.end());
		
	   line.erase( std::remove_if(line.begin(), line.end(), &ispunct),  //  
		line.end());
	  		appointments1.push_back(line);                      // nice and clean appointment
	  }
	//}

	//else cout << "Can't open file\n"; 
	return appointments1;
}

vector<int> read_file1(istream& file1)
{
  /*ifstream ist(file1.c_str());                            // error with this c_str
	if (!ist)
	{
		error ("Can't open the input file ", file1);
	}*/
	vector<int> dates;                // time to improvise, so we gonna store all the #s in here for now...
	int line;
	//if (file1.is_open())
	//{

	  while ( file1.good() )
	  {
	
		getline (file1,line);
		
		line.erase(
      std::remove_if(line.begin(), line.end(), &isalpha),    // removes words (alpha)
		line.end());
		
	   line.erase( std::remove_if(line.begin(), line.end(), &ispunct),  //  PUNCH THEM punctuations outta here!
		line.end());
	  		dates.push_back(line);
	  }
	//}

	//else cout << "Can't open file\n"; 
	return dates;
} 													// ok so now we have a dates vector,this vector is temporary and essential to make day and year vecotr [07032015]  month,days,year in each slot
	


	
                                   
vector<int> months1();							// we gonna load that vector and divide each slot by  1000000 since its int and not double, we will get the exact month
{
vector<int> dates = read_file1(file1.c_str());
for (int j = 0; j<dates.size()-1;++j){
		
	int	temp4 = dates[j] / 1000000 ;
		months1.push_back(temp4);
		}
		return months1;
}
		
		
		
vector<int> dayyear();            					// ok now we make another vector temporary call it dayyear,  by taking %  1000000 of  dates
{
vector<int> dates = read_file1(file1.c_str());

for (int j = 0; j<dates.size()-1;++j){
		int temp5 = dates[j] %1000000 ;
		dayyear.push_back(temp5);
		}
				return dayyear;
}

vector<int> days1;     // ok now we make  vector days1 divide temporary vector dayyear,  by /10000 gives us exact day.
{
vector<int>dayyear= dayyear();
for (int j = 0; j<dayyear.size()-1;++j){
		
	int	temp6 = dayyear[j] /10000 ;
		days1.push_back(temp6);
		}		
				return days1;
}
	
vector<int> years1;  // ok now we make  vector years1 modulo temporary vector dayyear,  by %10000 gives us exact year.
{
vector<int>dayyear= dayyear();
for (int j = 0; j<dayyear.size()-1;++j){
		
	int	temp7 = dayyear[j] %10000 ;
		years1.push_back(temp7);
		}
				return years1;
}
		
		
		

		
					
for (int j = 0; j<months1.size()-1 && j<years1.size()-1 && j<appointments1.size()-1;++j)
{
	int		temp1 = months1[j];
	int		temp2 = years1[j];
	string	temp3 = appointments1[j];	
		
	for(int i = 0; i<days1.size()-1;++i)
	{
		if (days1[i]> days1[i+1])
		{
			days1.push_back(i),
			months1.push_back(temp1);
			years1.push_back(temp2);
			appointments1.push_back(temp3);
		}
}
	}

	
	
	int main()
{	
	string file1;
	cout << "Please enter the name of the  input file \nEx: file1.txt \n";
	cin >> file1 
	 ifstream ist(file1.c_str());                            // error with this c_str
	if (!ist)
	{
		error ("Can't open the input file ", file1);
	}
	
	return 0;
}


There are two function overloads with the name "isdigit" in the standard library: int isdigit(int) and the template bool isdigit(CharT, const locale&);. You didn't say which one you wanted, so &isdigit is an attempt to take the address of an unresolved overloaded function, which cannot be compiled.

You can:
1) use a cast to request a particular overload: static_cast<int(*)(int)>(isdigit)
2) use a lambda: [](char c){return isdigit(c);}
3) (somewhat hackish) #include <ctype.h> (not cctype) and use the global namespace explicitly: ::isdigit
4) write a functor (if you don't have lambdas)
Topic archived. No new replies allowed.