vectors of classes & custom constructors

I have a vector of a class and need to use the push_back() function to add an unknown number of data to it. For each new instance of the class in the vector, I need to store 2 strings of data in it. I have a custom constructor in that class that takes 2 strings and stores them in the right variables in the class. I tried to use the following syntax to do this:

list.push_back(request, user);

where "list" is the name of the vector and "request" and "user" are the 2 strings the custom constructor needs, but this didn't seem to work, because the push_back() functions wants only 1 argument passed to it. How exactly would I go about doing this?
http://www.cplusplus.com/reference/stl/vector/

in this way
you can not use the vector container.
Last edited on
Sorry, my professor didn't spend a long time on vectors. Can you not make a vector of a class? Or is something else wrong? Looking on that page, it looks like to use push_back(), you have to give it the same data type as is stored in the vector. So i made a temporary instance of the class I'm using in the function, stored the data in there, then passed that temporary instance of the class to push_back(), but then I get some sort of error in ios_base.h

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
int main() {
#include<iostream>	
#include <string>
#include <vector>

using namespace std;

int main() 
{
	vector<string> s.vec(5);
	svec.push_back("example 1");
	svec.push_back("example 2");
	svec.push_back("example 3");
	svec.push_back("example 4");
	svec.push_back("example 5");
	
	for(int i = 0; i < svec.size(); i++ )
	{
		cout << svec[i] << " ";
	}

	return 0; 
}


Last edited on
I found out the problem is my class had an iobookstream class inside it, which is an object my professor gave us to talk to his server. It apparently didn't like being copied, so I had to get rid of the one in the class and just start passing another one by reference. Thanks for the help, though.
Topic archived. No new replies allowed.