On line 3 you resize() diner, but the pointers inside it are still pointing at random garbage. Then you attempt to access the data stored there, which could be anything. You will need to set them to something before you use them (probably using new, just don't forget to delete them when you are done).
But since I have an arbitrary number of items in the text file how do I create an array of an unknown size? and thanks to the person above for setting my indentation right :)
also when i use the displayRestaurant function to display the contents it displays the address of where the vector is at and not the contents themselves. dereferencing it is not working for some reason.
1 2 3 4 5 6 7 8 9 10
void displayRestaurants(vector<Restaurant*> diner, int count) {
if (count == 0) {
cout << "Error: no restaurants added or loaded yet" << endl;
return;
}
for (int i = 0; i < count; ++i) {
cout << diner[i];
cout << endl;
}
}
std::vector <obj*> objects;
objects.push_back(new obj); //push_back a new object
//...
for(unsignedint i = 0; i < objects.size(); ++i) {
objects[i]->foo(); //now we have an obj* in objects that points to something
}
//...
for(unsignedint i = 0; i < objects.size(); ++i) {
delete objects[i]; //make sure to delete them, since you newed them
}