I am trying to read a dat file using c++
that has different data types on each line. Address, description, square footage, bedrooms, bathrooms.
Here is the dat file:
123 N Main Avenue, Albiny, NY 12206
This is the first house description.
1200
3
1.1
456 S Lake Street, Los Angeles, CA 90057
This is the second house description
1000
4
2.0
This is the code I have:
char address[255] = { '\0' };
char description[255] = { '\0' };
int sqft = 0;
int bedrooms = 0;
float bathrooms = 0.0;
ifstream dataFile;
dataFile.open(fileName);
while (dataFile >> address >> description >> sqft >> bedrooms >> bathrooms)
{
House.setAddress(address);
House.setDescription(description);
House.setSqft(sqft);
House.setBedrooms(bedrooms);
House.setBathrooms(bathrooms);
cout << "Debug tool: check to see if it made it in this while loop." << endl;
}
It is not reading the file. My guess is that it is attempting to put 123 (the house number of the first address) into address
and it is not working because 123 is an int and not a string. How do I have each line get put into a variable so I can complete this operation?