help with importing into multiple arrays

I'm working on creating a program that will read a file with three lines of data. The lines are a string, int, int. They represent weather on a certain day of the year, so there's exactly 365 lines. I'm having trouble placing the data into their own arrays. I can't use structures on this, the way it is right now, I'm printing what seems like an infinite loop of random memory items printing in hex. This is what I've got. Help please! The file I'm importing from has the format:
10/6/2015 45 23
10/7/2015 54 34
etc.
etc.


int main(){
const int SIZE = 365;
ifstream in_file("weather_data.txt");
in_file.open("weather_data.txt");
while(true){

for(int i = 0; i < SIZE; i++){
string dates[SIZE];
int high_temps[SIZE];
int low_temps[SIZE];
in_file >> dates >> high_temps >> low_temps;
dates[i] = "";
high_temps[i] = i ;
low_temps[i] = i;
cout << dates << " " << high_temps << " " << low_temps << " " << endl;
}
}
}
Last edited on
firstly, use code formatting (<> to the right of the edit box)

The following should be outside your loop, you declare new arrays each time around.
1
2
3
string dates[SIZE];
int high_temps[SIZE];
int low_temps[SIZE];


Your in_file >> .... line is trying to read complete arrays, you need to index the items.
in_file >> dates[i] >> high_temps[i] >> low_temps[i];

These lines then become redundant.
1
2
3
dates[i] = "";
high_temps[i] = i ;
low_temps[i] = i;


And cout line also needs to specify individual elements rather than the entire array.
cout << dates[i] << " " << high_temps[i] << " " << low_temps[i] << " " << endl;;

The while loop should go, it will make you read from the file endlessly, the for loop takes the 365 rows that you need.
Topic archived. No new replies allowed.