Class and Vectors

So I have a weird problem with this code. I have two vectors of classes named winNames, and wines. wines reads information from the vector winNames. Everything works fine until I get to the information from the 3rd winNames, then I get a runtime error. My first thought was the vector winNames was running out of room, but that’s not the case. The size was what its supposed to be. Its always on the 3rd entry when 1 get the error. If I only enter two or less the whole program runs fine. Let me know if more information is needed Pleaser help!

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
string wn;
printSignature();

vector<WineryName*> winNames;
int street_number, zip_code;
string street, city, state, country;
	bool more = true;
	// loop to initilize winerys
while (more)
{
	cout << "Please enter the winery's name: (no to quit)";
	cin >> wn;
		if (wn == "no") 
		{
		more = false;
		}

	else
	{
		cout << "Please enter the street number: ";
		cin >> street_number;
		cout << "Please enter the street : ";
		cin.ignore();
		getline(cin,street);
		cout << "Please enter the city : ";
		getline(cin,city);
		cout << "Please enter the state : ";
		getline(cin, state);
		cout << "Please enter the zip code : ";
		cin >> zip_code;
		cout << "Please enter the country : ";
		cin.ignore();
		getline(cin, country);
	winNames.push_back(new WineryName(wn, street_number, street, city, state, zip_code,country));
	cout << endl;
	}
}
cout << endl; 
	// loop to initilize winerys ends
	
	// loop to initilize wines starts
vector<Wine*> wines;
string n, wt, wt2;
int sc, vin;
double p;
bool more1 = true;
while (more1) {

cin.ignore();
	cout << "Enter wine name: (no to quit)" ;
	getline (cin, n);

	if ( n == "no") more1 = false;
	else
	{
	
	cout << "Enter the wine type: ";
	getline (cin, wt);
	cout << "Enter the wine vintage: ";
	cin >> vin;
	cout << "Enter the wine score: ";
	cin >> sc;
	cout << "Enter the wine price: ";
	cin >> p;
	Wine* wine = new Wine(n);
		cout << "enter the winerys name:";
	string wineryname;
	cin.ignore();
	getline (cin, wineryname);
	
	wine->setWineryName(find(winNames, wineryname));
	wine->setWineInfo(n, p, sc);
	wine->setWineVintage(vin);
	wine->setWineType(wt);
	wines.push_back(wine);
	}
}
> Let me know if more information is needed
provide enough to reproduce your problem.

http://www.eelis.net/iso-c++/testcase.xhtml
Topic archived. No new replies allowed.