Help-my code reads small files but not large

Hello, I'm trying to make part of a code that reads a csv file with data containing the date and time, and the wind speed at that time, then does various output things.
When I copy and paste 1000 entriesinto a csv file and ru it, it works great, but if I use the file thats about 6,000kb it misses every second date and time part out, code anyone help me with this?

heres my code:

#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <string>
#include <ctime>
#include <FileHC.h>

using namespace std;

int main ()
{


ofstream outFile("C:\\WindSpeedAnswer.csv");
if (!outFile) {
cout<< "error opening file"<<endl;
return -1;
}


ifstream inFile ("C:\\Copy of Kirkwall_23_hm_proc15.csv");
string line;
int linenum = 0;
if (inFile.is_open())
{
double randomMax;
double randomMin;
cout<<"would you like to add a random varience, enter 'yes' if you do "<<endl;
string Question;
cin >> Question;
string answerYes= "yes";
if (Question==answerYes){
cout<<"enter the max value of random varience "<<endl;
cin>>randomMax;
randomMax=randomMax-1;


cout<<"enter the min value of random varience "<<endl;
cin>>randomMin;
randomMin=randomMin-1;}




while (getline (inFile, line))
{
linenum++;
// cout << "\nLine #" << linenum << ":" << endl;
istringstream linestream(line);
string item;
int itemnum = 0;

while (getline (linestream, item, ','))
{
itemnum++;
double WindSpeed=0;
string DateAndTime;




//cout << "Item #" << itemnum << ": " << item << endl;
if (itemnum%2 == 1) {

DateAndTime=item;


string replace= "-99999";


while(DateAndTime==replace){
DateAndTime= "Data Missing";}

cout<<"at "<<DateAndTime<<endl;
outFile<< DateAndTime<<"," ;}


if (itemnum%2 == 0) {

WindSpeed=atof(item.c_str());

if(WindSpeed==-99999){

WindSpeed=9;
}

if (Question==answerYes){
for(int index=0; index<itemnum; index++){
double X = randomMax+ rand() * (randomMax - randomMin) / RAND_MAX;
if (randomMin<X<randomMax){
WindSpeed=X;}
}}



cout<<"the wind speed is "<<WindSpeed<<","<<endl;

outFile<<WindSpeed<<","<<endl;
//outFile.write(WindSpeed);
}
}
}
// cout<< "at "<<DateAndTime<<" the wind speed is "<<WindSpeed<<endl;
inFile.close();
}

else cout << "Unable to open file";



outFile.close();

char stopchar;
cin>>stopchar;
return 0;
}
Does it miss every second date and time part out from the start of the large file?

Maybe there is an error in a line of the large csv file that causes the problem.

EDIT:

Unrelated to your problem bu you will need to correct this line.

if (randomMin<X<randomMax){

e.g. if ((randomMin<X) and (X<randomMax)){
Last edited on
Topic archived. No new replies allowed.