Hi i'm making a function that will return make a series of strings and perform a function returning a value for each. I've stored the strings in one vector v, and the integer values in another v2. Then it is supposed to return the string that corresponds to the smallest value in v2. I'm trying to pushback the vector for each time the for loop is run, but I get an error saying there is no such function "push_back" to call. What am I doing wrong here? I'm compiling on quincy by the way.

Thanks for the help!

string mutated_chooser(string origmutated,string orisentance, int offspringnumber,int rate){
std::vector <string> v;
std::vector <int> v2;

	for (int t=0; t=offspringnumber-1;t++){
		string newmutated= mutatedstring(origmutated,rate);
		int matchnumber= match(orisentance,newmutated);
	int min_index=min_element( v2.begin(), v2.end() ) - v2.begin();
	string closest =v[min_index];
	return v[min_index];

Only thing I can think of is the includes that you have..

You need <vector>, <iostream>

It probably said that std::vector<string> has no function push_back(int) because on line 6 you say v.push_back(1), but v is a string vector, not an int vector.

In "push_back()" you are supposed to input the value which you are adding to the vector.

For example, v.push_back("hello")

Perhaps you were under the impression that the value you put in push_back is the number of new slots being created. I believe your code should look like this:

for (int t=0; t=offspringnumber-1;t++){
		string newmutated= mutatedstring(origmutated,rate);
		int matchnumber= match(orisentance,newmutated);

You don't actually have to use "t" inside the for loop since the push_back function automatically sticks the new value on the end.

Spot on! Thank you

Thanks, I filled the parameters of the vectors with the appropriate strings and integers. As mareoraft said I assumed the push_back function only did push back the vector the parameter's amount and didn't realise it actually filled the new element with the parameter.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.