Thank you all for the reply. So some of you asked what the input code looks like. Here it is:
1 2 3 4 5 6 7 8
|
Kauai
310
5
Gorgeous views.
3
Long lines for the bathrooms on this one.
4.5
The gnats are annoying on this tour.
|
Where 5 gets input into *tourLength[] and "Gorgeous views" gets input into *remarks[] but all are within the array of structs *tours[i].
So there are three different tour lengths and 3 remarks about each tour length. The output should look something like this:
Tour: Kauai
Tour Code#: 310
Tour #1 Length (hrs): 5
Remarks about this tour: Gorgeous views.
Tour #2 Length (hrs): 3
Remarks about this tour: Long lines for the bathrooms on this one.
Tour #3 Length (hrs): 4.5
Remarks about this tour: The gnats are annoying on this tour.
In reply to: keskiverto,.
Thank you for showing me the different ways to achieve that. In this certain assignment he wants us using -> instead of the . operator. Why I didn't allocate memory within the scruct itself is that the assignment specifically states to define a dynamic array within the program and then fill those with the data from the file. So to define a new dynamic array within the file I assigned the *tourPtr->tourLength = new float[DETAILS];.
When doing the below, as suggested by many of you, the program works flawlessly.
1 2 3 4 5 6 7 8 9 10 11 12
|
struct Tours{
string name;
int number;
float *tourLength = new float[DETAILS]; //dynamic array
string *remarks = new string[DETAILS]; //dynamic array
~Tours(){
if(tourLength) delete [] tourLength;
tourLength = nullptr;
if(remarks) delete [] remarks;
remarks = nullptr;
}//destructor
};//tours
|
However, the problem was that the instructor specifically requires us to define two new dynamic arrays for the float and string values and then input the file data into those two new dynamic arrays which fill the struct dynamic arrays.
That is where the problem was occurring I believe... the defining two new arrays and assigning the values to them and having them assign to the struct arrays.
ne555 and
seeplus, Thank you both very much. With your feedback I was able to fix a few things and removed the fin.ignore() from after the getline. That was my mistake I did not intend to have it after the getline.
I was able to get the program running perfectly by following suggestions from everyone and tweaking my code around. Thank you all so much for the assistance, guidance and suggestions. I appreciate you all.