I am having a bit of trouble on reading data in a specific format into different variables. I need to read the data from the file and store into 5 different variables of different variable types.(string Name, string Fish, string Location, float Length, float Weight)
The format of the Data I am trying to store is as follows:
Picture of How Data is Stored in File
I have no issues obtaining the name, fish, and location from the file using the getline() function. My issue comes with the length and width.
ifstream file("test.txt");
while(file.good())
{
getline(file, Name);
getline(file, Species);
getline(file, Location);
file >> Length;
file >> Weight;
cout << Name << "\n" << Species << "\n" <<Location << "\n" <<Length << "\n";
}
When I use the following code the output becomes wonky and it prints the data out of order after the first listing. Any help with this would be greatly appreciated.