Hi everyone, new to the DaniWeb community, i have always used it for homework help in the past, but i'm about to rip my hair out if i stare at this code for another hour.
basically the project is to write a code that reads data from a file, gets the name, hitemp, lotemp, and avgrainfall from the input, to be used in later functions. Seemed very simple about a week ago, but the File I/O combined with the Getline() and array of structs is prooving to be a challenge.
It just seems like there isn't a problem, but it won't work! I believe its my getline functions.
The code compiles correctly in VS8.0, but as soon as command prompt opens, windows closes the window and i get this huge error message (running Windows 7 pro).
I'm sure its something stupid, but if anyone can see anything wrong with this please let me know, otherwise I'm going to assume its my computer (again... ;) )
Thanks!
#include<iostream>
#include<iomanip>
#include<string>
#include<fstream>
using namespace std;
struct WeatherInfo
{
string city;
double TotRain;
double TempHi;
double TempLo;
double TempAvg;
};
ifstream infile;
void fillCities(WeatherInfo Rain [], int &);
int main()
{
int NumCities;
WeatherInfo Rain[30];
infile.open("prog1.txt");
fillCities(Rain, NumCities);
infile.close();
return 0;
}
void fillCities(WeatherInfo Rain [], int &NumCities)
{
string CityName;
int i = 0;
getline(infile, CityName);
while ( !infile.eof() )
{
Rain[i].city = CityName;
infile >> Rain[i].TotRain;
infile >> Rain[i].TempHi;
infile >> Rain[i].TempLo;
infile.ignore();
getline(infile, CityName);
i++;
}
NumCities = i;
}