I'm opening file in 1 function and trying to use pointer of that in other function. But i dunno why its not working. Below is the Code.
void ReadFile()
{
float data;
int total_rows, pairs;
double longitude, latitude;
{
GsmFingreprintEuc *g;
ll.push_front(new GsmFingreprintEuc);
if(file_ptr.is_open())
cout<<"Yes!!"<<endl;
else
cout<<"NO!!"<<endl;
file_ptr >> data;
total_rows = data;
cout<<"Total Rows:"<<total_rows<<endl;
for (int i = 0; i < total_rows; i++)
{
g = ll.front();
file_ptr >> data;
pairs = data;
for (int j = 0; j < pairs; j++)
{
int id;
double value;
file_ptr >> data;
id = data;
file_ptr >> data;
value = data;
g->add_map(id, value);
}
file_ptr >> data;
latitude = data;
g->set_latitude(latitude);
file_ptr >> data;
longitude = data;
g->set_longitude(longitude);
}
}
cout<<"Size: "<<ll.size()<<endl;
}
DtFileReaderEuc(string file_path)
{
cout << "I am in Constructor" << endl;
cout << file_path << endl;
fstream file_ptr(file_path.c_str(), std::ios_base::in);
if (file_ptr.is_open()) {
cout << "Yahhy!! file Opend successfully" << endl;
float data;
file_ptr >> data;
double total_rows = data;
cout<<"Total Rows:"<<total_rows<<endl;
//file_ptr = myfile;
ReadFile();
//myfile.close();
} else
cout << "Wohoo!! Wrong path" << endl;
cout << "Done!!" << endl;
}
};
and when i rund this code output is: "I am in Constructor /home/umar/Desktop/DataFile/dha_dataset.gfp Yahhy!! file Opend successfully Total Rows:7257 NO!! Total Rows:0 Size: 1 Done!!"
Thanks in advance