pushback error using vectors

would appreciate som wisdom on why the code has an error on a pushback function.
all help or info on how to resolve is welcome. ERROR IS ON LINE 178

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
170
171
172
173
174
175
176
177
178
179
180
181
//HEADER
#pragma once
#include<iostream>
#include<vector>
#include<string>
using namespace std;

#ifndef TRANSPORT_H
#define TRANSPORT_H

class trans {
public:
	trans();
	trans(string aName, string anXoLoc, string anXfLoc, string aTime, string aCellNum);
	void setName(string aName);
	void setXoLoc(string anXoLoc);
	void setXfLoc(string anXfLoc);
	void setTime(string aTime);
	void setCellNum(string aCellNum);
	string getName();
	string getXoLoc();
	string getXfLoc();
	string getTime();
	string getCellNum();

private:
	string name;
	string xoLoc; //offices
	string xfLoc; //destination
	string time;
	string cellNum;
};


//SOURCE
#include"transport.h"

trans::trans() {
	setName("");
	setXoLoc("");
	setXfLoc("");
	setTime("");
	setCellNum("");
}

trans::trans(string aName, string anXoLoc, string anXfLoc, string aTime, string aCellNum) {
	setName(aName);
	setXoLoc(anXoLoc);
	setXfLoc(anXfLoc);
	setTime(aTime);
	setCellNum(aCellNum);
}

void trans::setName(string aName) {
	name = aName;
}

void trans::setXoLoc(string anXoLoc) {
	xoLoc = anXoLoc;
}

void trans::setXfLoc(string anXfLoc) {
	xfLoc = anXfLoc;
}

void trans::setTime(string aTime) {
	time = aTime;
}

void trans::setCellNum(string aCellNum) {
	cellNum = aCellNum;
}

string trans::getName() {
	return name;
}

string trans::getXoLoc() {
	return xoLoc;
}

string trans::getXfLoc() {
	return xfLoc;
}

string trans::getTime() {
	return time;
}

string trans::getCellNum() {
	return cellNum;
}

#endif

//MAIN
#include"transport.h"

void inputInfo(vector<trans> &);
void displayInput(vector<trans>&);
void separateP(vector<trans>&);

vector<trans> myVector;
vector<trans> rioLoc, mayaLoc, elseLoc;

string name;
string xoLoc; //offices
string xfLoc; //destination
string time;
string cellNum;

//main not ready. Creating each function one by one to them make it look nice
int main() {
	int option;
	do {
		cout << "MENU"
			<< endl << "1) input "
			<< endl << "2) output ";
		cin >> option;

		switch(option){
		case 1:
			inputInfo(myVector);
			break;
		case 2:
			displayInput(myVector);
			break;
		}
	} while (option != 3);
	system("pause");
}

void inputInfo(vector<trans> &newMyVector) {
	int charSize;
	cout << "How many passangers to register: ";
	cin >> charSize;

	for (int x = 0; x < charSize; ++x) {
		cout << "Passanger #" << x + 1 << endl;
		
		cout << "Name of passanger: ";
		cin >> name;

		cout << "Office: ";
		cin >> xoLoc;

		cout << "Destination: ";
		cin >> xfLoc;

		cout << "Time of pickup: ";
		cin >> time;

		cout << "Cellphone: ";
		cin >> cellNum;

		if (charSize != 0)
			newMyVector.push_back(trans(name, xoLoc, xfLoc, time, cellNum));
	}
}

void displayInput(vector<trans>& newMyVector) {
	for (int x = 0; x < newMyVector.size(); ++x) {
		if (x == 0) {
			cout << "There are " << newMyVector.size() << " passengers. These are: " << endl;
		}
		cout << "-----------------------------Passenger #" << x + 1 << endl;
		cout << newMyVector[x].getName() << endl;
		cout << newMyVector[x].getXoLoc() << endl;
		cout << newMyVector[x].getXfLoc() << endl;
		cout << newMyVector[x].getTime() << endl;
		cout << newMyVector[x].getCellNum() << endl;
	}
}

void separateP(vector<trans>& newMyVector) {
	for (int x = newMyVector.size() - 1; x >= 0; --x) {
		if (newMyVector[x].getXoLoc() == "rio") {
			rioLoc.push_back(newMyVector[x].getXoLoc()); //ERROR IS HERE ON THE PUSHBACK
		}
	}
}


this is what the error says:

Error (active) E0304 no instance of overloaded function "std::vector<_Ty,_Alloc>::push_back [with _Ty=trans, _Alloc=std::allocator<trans>]" matches the argument list dataPractice2 C:\Users\javye\source\repos\dataPractice2\dataPractice2\main.cpp 82

and also:

Error C2664 'void std::vector<trans,std::allocator<_Ty>>::push_back(_Ty &&)': cannot convert argument 1 from 'std::string' to 'const _Ty &' dataPractice2 c:\users\javye\source\repos\datapractice2\datapractice2\main.cpp 82

Last edited on
rioLoc is a vector of trans.
You are trying to push a string.
Maybe you just want to push newMyVector[x] ?
Or should rioLoc be a vector of strings ?
rioLoc should be a vector of strings. What this function should do is that when the user enters the string "rio", all the information of the passenger will be stored on rioLoc apart from other passangers.
Topic archived. No new replies allowed.