help with functions of vectors

Ok I am working a project, finished all requirements, except I wrote my code under int main(), we were told to make all codes in a function and then just load anything necessary to int main()

My question is when I was making my code into function loading each other I ran into these errors, and being new to c++ I couldnt fix them.

Error code in my last post
Can someone please help me? I honestly don't know how to fix it.
How do I fix this error line
1
2
inputappointments.cpp:43:56: error: no matching function for call to âremove_if(std::basic_string<char>::iterator, std::basic_string<char>::iterator, <unresolved overloaded function type>)â
inputappointments.cpp:43:56: note: candidate is:

-----------------------------

inputappointments.cpp:20:1: error: âvectorâ does not name a type
inputappointments.cpp:51:1: error: âvectorâ does not name a type
inputappointments.cpp:85:1: error: âvectorâ does not name a type
inputappointments.cpp:86:1: error: expected unqualified-id before â{â token
-------------------------------------------------------------------------


I will post the code from my desktop right now
ignore comments please meant to be joke for my partner who is working on other part of the project.
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
// let me know if this works, or if you want me to edit and do something.  Also feel free to delete this  and any other silly comment u don't like
// I usually don't comment on any of my source files since I am lazy, but I added some comments so you see what I did.

/*
void printer(vector<double>& v, const string& name)    //  Hw 2  how to print vectors. use it to print vector at bottom
	// printer doubles to cout
	{
	cout << name << ": (" << v.size() << ") {";
	for (int i = 0; i<v.size(); ++i) {
		if (i%8==0) cout << "\n   ";	// to avoid long lines
		cout << v[i];
		if (i<v.size()-1) cout << ", ";	// messy; to avoid a trailing comma
	}
	cout << "\n}\n";
*/	
	


vector<string> read_file(istream& file1)
{
ifstream ist(file1.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),  //  PUNCH THEM punctuations outta here!
		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());
	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()
{	
	cout << "Please enter the name of the  input file \nEx: file1.txt \n";
	string file1;
	cin >> file1 
	 // int numdiff = diff_files_by_name(file1);
	// cout << "Number of different lines: " << numdiff << "\n";
	return 0;
}
Last edited on
Maybe you have not included <vector> or you have to write std::vector.
added

1
2
3
4
5
6
#include "std_lib_facilities_3.h"	
#include <iostream>
#include <vector>
#include <fstream>
#include <iterator>
#include <algorithm> 


and now it looks really scary.... 1 page of errors.
Last edited on
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
inputappointments.cpp: In function âVector<String> read_file(std::istream&)â:
inputappointments.cpp:27:20: error: âstd::istreamâ has no member named âc_strâ
inputappointments.cpp:30:45: error: invalid user-defined conversion from âstd::istream {aka std::basic_istream<char>}â to âintâ [-fpermissive]
In file included from /usr/include/c++/4.7/ios:45:0,
                 from /usr/include/c++/4.7/ostream:40,
                 from /usr/include/c++/4.7/iterator:64,
                 from /usr/include/c++/4.7/regex:44,
                 from std_lib_facilities_3.h:28,
                 from inputappointments.cpp:18:
/usr/include/c++/4.7/bits/basic_ios.h:113:7: note: candidate is: std::basic_ios<_CharT, _Traits>::operator void*() const [with _CharT = char; _Traits = std::char_traits<char>] <near match>
/usr/include/c++/4.7/bits/basic_ios.h:113:7: note:   no known conversion for implicit âthisâ parameter from âvoid*â to âintâ
inputappointments.cpp:43:56: error: no matching function for call to âremove_if(std::basic_string<char>::iterator, std::basic_string<char>::iterator, <unresolved overloaded function type>)â
inputappointments.cpp:43: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, class _Predicate> _FIter std::remove_if(_FIter, _FIter, _Predicate)
/usr/include/c++/4.7/bits/stl_algo.h:1160:5: note:   template argument deduction/substitution failed:
inputappointments.cpp:43:56: note:   couldn't deduce template parameter â_Predicateâ
inputappointments.cpp:46:66: error: no matching function for call to âremove_if(std::basic_string<char>::iterator, std::basic_string<char>::iterator, <unresolved overloaded function type>)â
inputappointments.cpp:46: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, class _Predicate> _FIter std::remove_if(_FIter, _FIter, _Predicate)
/usr/include/c++/4.7/bits/stl_algo.h:1160:5: note:   template argument deduction/substitution failed:
inputappointments.cpp:46:66: note:   couldn't deduce template parameter â_Predicateâ
inputappointments.cpp: In function âVector<int> read_file1(std::istream&)â:
inputappointments.cpp:58:20: error: âstd::istreamâ has no member named âc_strâ
inputappointments.cpp:61:45: error: invalid user-defined conversion from âstd::istream {aka std::basic_istream<char>}â to âintâ [-fpermissive]
In file included from /usr/include/c++/4.7/ios:45:0,
                 from /usr/include/c++/4.7/ostream:40,
                 from /usr/include/c++/4.7/iterator:64,
                 from /usr/include/c++/4.7/regex:44,
                 from std_lib_facilities_3.h:28,
                 from inputappointments.cpp:18:
/usr/include/c++/4.7/bits/basic_ios.h:113:7: note: candidate is: std::basic_ios<_CharT, _Traits>::operator void*() const [with _CharT = char; _Traits = std::char_traits<char>] <near match>
/usr/include/c++/4.7/bits/basic_ios.h:113:7: note:   no known conversion for implicit âthisâ parameter from âvoid*â to âintâ
inputappointments.cpp:70:22: error: no matching function for call to âgetline(std::istream&, int&)â
inputappointments.cpp:70: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 provided
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 _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::getline(std::basic_istream<_CharT, _Traits>&, std::basic_string<_CharT, _Traits, _Alloc>&)
/usr/include/c++/4.7/bits/basic_string.h:2792:5: note:   template argument deduction/substitution failed:
inputappointments.cpp:70:22: note:   mismatched types âstd::basic_string<_CharT, _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 _CharT, class _Traits, class _Alloc> std::basic_istream<_CharT, _Traits>& std::getline(std::basic_istream<_CharT, _Traits>&, std::basic_string<_CharT, _Traits, _Alloc>&, _CharT)
/usr/include/c++/4.7/bits/basic_string.tcc:1070:5: note:   template argument deduction/substitution failed:
inputappointments.cpp:70:22: note:   mismatched types âstd::basic_string<_CharT, _Traits, _Alloc>â and âintâ
inputappointments.cpp:72:8: error: request for member âeraseâ in âlineâ, which is of non-class type âintâ
inputappointments.cpp:73:27: error: request for member âbeginâ in âlineâ, which is of non-class type âintâ
inputappointments.cpp:73:41: error: request for member âendâ in âlineâ, which is of non-class type âintâ
inputappointments.cpp:74:8: error: request for member âendâ in âlineâ, which is of non-class type âintâ
inputappointments.cpp:76:10: error: request for member âeraseâ in âlineâ, which is of non-class type âintâ
inputappointments.cpp:76:37: error: request for member âbeginâ in âlineâ, which is of non-class type âintâ
inputappointments.cpp:76:51: error: request for member âendâ in âlineâ, which is of non-class type âintâ
inputappointments.cpp:77:8: error: request for member âendâ in âlineâ, which is of non-class type âintâ
inputappointments.cpp: At global scope:
inputappointments.cpp:91:1: error: expected unqualified-id before â{â token



sorry for spam, and I find fixing it hopeless
Can someone help me out with this? I don't even know where to begin.

1
2
27:20: error: âstd::istreamâ has no member named âc_strâ
inputappointments.cpp:30:45: error: invalid user-defined conversion from âstd::istream {aka std::basic_istream<char>}â to âintâ [-fpermissive]


What does this even mean?

1
2
3
4
5
/* ifstream ist(file1.c_str());
	if (!ist)
	{
		error ("Can't open the input file ", file1);
	}  */

I blocked this part of the code, but still so many errors.
Look at your variable on line 19. It is an istream object, not ifstream.
Did you follow Peter87's suggestion of using std::vector?

Maybe you should post all your code - if there is not too much of it.
@TheIdeasMan

the code is on my first page

I am trying to turn the vectors I made in Int Main() into functions that I only load what it stores . So I can load that inside my int main part.


But yea my code is on the first page.
Want me to explain what my code does?
Are you using istreams as your parameters on purpose? Or did you mean ifstreams? Either way, neither class has a c_str() member function. You should extract the data to a string first, then you can use the string member function c_str().
1
2
3
file >> MyString;
if(MyString.c_str() /*...*/){
//... 
updated version.

I put the file into a string then
ifstream ist(file1.c_str()); and I use it in line 19 and line 50 for

the line 19 vector to remove all int and punctuation and file 50 to remove alpha and punctuation .

file1 is a string I made in int main().


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
	
#include "std_lib_facilities_3.h"	
#include <iostream>
#include <vector>
#include <fstream>
#include <iterator>
#include <algorithm> 

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),  //  PUNCH THEM punctuations outta here!
		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;
}


Topic archived. No new replies allowed.