Im familiar with fstream and know how to read in data, given that there is
one type per line.
But I have a file that has multiple lines each containing a string (an address) and two double values (latitude and longitude).
Can anyone help with the logic part of reading in data and initializing them to member variable.
struct CountryMap
{
char sCountry[20];
double dlat;
double dlong;
};
int main()
{
ifstream fstrm("sample.txt");
CountryMap cmap;
if(fstrm.is_open())
while( fstrm>>cmap.sCountry>>cmap.dlat>>cmap.dlong )
{
cout << "Retrieved Country[" << cmap.sCountry << "]Latitude[" <<cmap.dlat << "]Longitude["<<cmap.dlong<<"]\n";
//do what you like here with place, latitude, longitude. Store to a vector<CountryMap> if you like for further processing....
}
fstrm.close();
fstrm.clear();
}
OUTPUT
----------
for the same sample.txt above
$ ./out
Retrieved Country[INDIA]Latitude[21]Longitude[78]
Retrieved Country[AUSTRALIA]Latitude[35.3]Longitude[149.12]