my program is giving the Segmentation violation error. Please could you help me figure the error.
ifstream in;
in.open("Temperature01-12-2021-09-12-2021.txt");
int lincent;
float date_index;
double temperature;
vector <float> date;
vector <float> temp;
ULong64_t first_timestamp;
ULong64_t last_timestamp;
TCanvas* mianCanvas = new TCanvas("miancanvas");
while(!in.eof())
{
in>>date_index>>temperature;
lincent++;
date.push_back(date_index);
temp.push_back(temperature);
}
printf("%d", lincent);
TGraph* graph = new TGraph(lincent);
graph->SetMarkerStyle(7);
graph->SetMarkerColor(kRed);
graph->SetLineColor(kRed);
graph->GetXaxis()->SetTimeDisplay(1);
graph->GetXaxis()->SetTimeFormat("%Y-%m-%d %H:%M:%S %F 1970-01-01 00:00:00");
first_timestamp = (date.data())[0];
last_timestamp = (date.data())[lincent-1];
TTimeStamp first_ts(first_timestamp);
TTimeStamp last_ts(last_timestamp);
for(int i = 0; i < lincent; i++)
{
graph->SetPoint(i, (date.data())[i], (temp.data())[i]);
}
graph->SetTitle(Form("%d-%d", first_ts.GetDate(), last_ts.GetDate()));
graph->GetXaxis()->SetTitle("Time");
graph->GetYaxis()->SetTitle("Current (A)");
graph->Draw("ALP");
return 0;