vector issues

Hey guys,

I'm new at c++ and trying to learn it on my own...the code below is being annoying for some reason the last bit where it says
1
2
3
4
5
6
cout << "Would you like to display the vector?";
		cin >> s;
		if (s == "y"){
			for (int j = e.size; j>0; j--){
				cout << e[j];
			}


keeps giving me an error at cout << e[j]; saying <<are undefined...I know it has to do with my vector object e but I dont know what it is....halp
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
#include"employee.h"
#include"Engineer.h"
#include<vector>


int main(){
	string s;
	int v;
	vector<employee> e;
	cout << "Would you like to add an employee? ";
	cin >> s;
	if (s == "y"){
		string ans;     //Answer For which employee
		
		cout << "Choose wisely my son:   " << endl << "a) Engineer    b) researcher" << endl;
		cin >> ans;
		if (ans == "a"){ 
			cout << "You have choosen an engineer";
			engineer eng;
			cout << "How many days off does he get?";
			cin >> v;
			eng.SetVdays(v);
			cout << "Does the engineer know Cpp?   y or n";
			cin >> s;
			if (s == "y"){ eng.engineercpp(); }
			else { cout << "He doesnt know cpp"; }
			
			for (int i = 0; i < 100; i++){
				e.push_back(eng);
			}

		}
		if (ans == "b"){ 
			cout << "You have choosen a reseacher";

		}
		else{ cout << "its a or b bro"; return main(); } //try to go back to the question instead..but later
	
	
		cout << "Would you like to display the vector?";
		cin >> s;
		if (s == "y"){
			for (int j = e.size; j>0; j--){
				cout << e[j];
			}

	}

}
The cout does not know how to print an employee, you have to provide your own << method.

See the following code for an example:

1
2
3
4
5
ostream& operator << (ostream &s, const employee &e)
{
    s << e.name << e.id;  // something like that
    return s;
}


And then you could use cout to print your employee object.
Thank you, how would the for loop know to print say the first object in the vector as opposed to the second or 3rd?
Topic archived. No new replies allowed.