dimanche 27 mars 2016

ifstream giving me trouble

im using fstream to get visual studio to read a file with about 100 lines of repeated info, just different values every line. Im using a count variable to keep track of how many times this is read, but it keeps saying 0. i know the file is being opened because i placed an If statement to check for me. and yes the file im reading from is also the location of my cpp file. If you could take a look and tell me what im missing i would appreciate it!

#include<iostream>
#include<iomanip>
#include<fstream>
#include<string>
using namespace std;

int main() {
//file variables
string date;
int rainIn, minTempF, maxTempF;

//variables
int count = 0;
double totalRain = 0;
double averageMinimumTemp = 0;
double averageMaximumTemp = 0;
double overallMaxTemp = 0;
double overallMinTemp = 0;

ifstream inFile("2014WeatherData.txt");

if (!inFile) {
    cout << "Error: Input File Cannot Be Opened\n";
    exit(EXIT_FAILURE);
}

//read file records
while (inFile >> date >> rainIn >> maxTempF >> minTempF) {
    count++
}

cout << count << " Records read\n";

return 0;
}

im only in computer science 1, so im still learning any feedback will be very much appreciated!!

Aucun commentaire:

Enregistrer un commentaire