S
Siddharth Taneja
Hi,
I have a very simple prg over here, trying to read the lines of a file
#include <iostream>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main() {
char tempn[100];
char line[40];
fstream f;
sprintf(tempn,"%s/%s\0","/root/somedir/prj1/","temp.cfg");
f.open(tempn,ios::in); // open file for reading
if(!f) {
cout<<"Could not find network.cfg in the directory"; // couldnt open
it
}
while(f.getline(line,10)) {
cout<<" i am in"<<endl;
if(f.eof())
break;
}
}
/* */ cout<<"f "<<f<<endl; //what is the file descpr
f.close();
delete [] tempn;
return 1;
}
when i run this prg and try to read a file of 6 lines, it prints 'i am
in' 6 times but the file descrp. is printed out as 0. While if I print
the value of the file descrp within the loop, it is ok.Why is that
happening?
Thanks
Sidhu
I have a very simple prg over here, trying to read the lines of a file
#include <iostream>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
int main() {
char tempn[100];
char line[40];
fstream f;
sprintf(tempn,"%s/%s\0","/root/somedir/prj1/","temp.cfg");
f.open(tempn,ios::in); // open file for reading
if(!f) {
cout<<"Could not find network.cfg in the directory"; // couldnt open
it
}
while(f.getline(line,10)) {
cout<<" i am in"<<endl;
if(f.eof())
break;
}
}
/* */ cout<<"f "<<f<<endl; //what is the file descpr
f.close();
delete [] tempn;
return 1;
}
when i run this prg and try to read a file of 6 lines, it prints 'i am
in' 6 times but the file descrp. is printed out as 0. While if I print
the value of the file descrp within the loop, it is ok.Why is that
happening?
Thanks
Sidhu