mardi 22 février 2022

Reading files and output is skipping lines

This is homework but im stuck wondering where i went wrong. any help from you experts would be appreciated greatly!

Intended Output : Date: 31/3/2016 Time: 09:00 Speed: 6

Date: 31/3/2016 Time: 09:10 Speed: 5

Date: 31/3/2016 Time: 09:20 Speed: 5

Date: 31/3/2016 Time: 09:30 Speed: 5

Date: 31/3/2016 Time: 09:40 Speed: 6

and so on, basically in sequence

Current output Date: 31/3/2016 Time: 22:20 Speed: 4

Date: 31/3/2016 Time: 22:40 Speed: 4

Date: 31/3/2016 Time: 23:0 Speed: 3

Date: 31/3/2016 Time: 23:20 Speed: 4

Date: 31/3/2016 Time: 23:40 Speed: 5

as you can see, its skipping in 20mins interval. im not sure where in my code is causing this.

#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include "Date.h"
#include "Time.h"
#include "Vector.h"

using namespace std;
typedef struct {
    Date d;
    Time t;
    float speed;
} WindLogType;

ostream & operator <<( ostream & os, const WindLogType& wl );
istream & operator >>( istream& input, WindLogType& wl );

int main()
{   Vector<WindLogType> windLogs;
    string day,month,year,hours,minss,strInput;
    string test;
    WindLogType windlogs2;
    ifstream infile("test2.csv");
    if(!infile) return -1;

infile >> windlogs2;
while (!infile.eof()){
//infile >> windlogs2;

getline(infile,strInput); //skip the first line
getline(infile, strInput, '/');
windlogs2.d.SetDay(stoi(strInput));
getline(infile,strInput, '/');
windlogs2.d.SetMonth(stoi(strInput));
getline(infile,strInput, ' ');
windlogs2.d.SetYear(stoi(strInput));
getline(infile,strInput, ':');
windlogs2.t.SetHours(stod(strInput));
getline(infile,strInput,',');
windlogs2.t.SetMins(stod(strInput));
getline(infile,strInput,',');
getline(infile,strInput,',');
getline(infile,strInput,',');
getline(infile,strInput,',');
getline(infile,strInput,',');
getline(infile,strInput,',');
getline(infile,strInput,',');
getline(infile,strInput,',');
getline(infile,strInput,',');
getline(infile,strInput,',');
windlogs2.speed = (stof(strInput));
getline(infile,strInput,',');
getline(infile,strInput,',');
getline(infile,strInput,',');
getline(infile,strInput,',');
getline(infile,strInput,',');
getline(infile,strInput,',');
getline(infile,strInput,',');

ofstream outfile("outputFile.txt.");
outfile << windlogs2 << '\n';
cout << windlogs2 << '\n';



 }

    return 0;
    
}

ostream & operator <<( ostream & os, const WindLogType& wl )
{
    os << wl.d << wl.t << " Speed: " << wl.speed << '\n';

        return os;
}
istream & operator >>( istream& input, WindLogType& wl )
{
    input >> wl.d >> wl.t >> wl.speed;
    return input;
}

Aucun commentaire:

Enregistrer un commentaire