ifstream question
-
Does anyone know how to get file size, if i work with files using ifstream class?
-
Does anyone know how to get file size, if i work with files using ifstream class?
#include #include using namespace std; void main() { ifstream in("c:/boot.ini"); in.seekg(0, ios::end); //set file-stream pos at end streampos ps = in.tellg(); //get the pos cout << "File size: " << ps << endl; //file size by "byte" in.close(); //close... }
-
Does anyone know how to get file size, if i work with files using ifstream class?
Following should work.
int fh = _open(_file name_, _O_APPEND , _S_IREAD | _S_IWRITE ); int filesize = _filelength(fh);
Above code needs following header files 1. io.h 2. fcntl.h 3. sys\stat.h I don't now how can we get file size using ifstream.h. I used above to get it. We Believe in Excellence -
Following should work.
int fh = _open(_file name_, _O_APPEND , _S_IREAD | _S_IWRITE ); int filesize = _filelength(fh);
Above code needs following header files 1. io.h 2. fcntl.h 3. sys\stat.h I don't now how can we get file size using ifstream.h. I used above to get it. We Believe in Excellence -
#include #include using namespace std; void main() { ifstream in("c:/boot.ini"); in.seekg(0, ios::end); //set file-stream pos at end streampos ps = in.tellg(); //get the pos cout << "File size: " << ps << endl; //file size by "byte" in.close(); //close... }
Thanks a lot!!! Now i want to read the file into the memory and work with this memory like i worke as with file, i think using istream, but i can't make the istream object... Here is my code:
ifstream shapefilef(ShapeFileName.c_str(),ios::binary); shapefilef.seekg(0,ios::end); streampos ps = shapefilef.tellg(); int size = ps.seekpos(); char* data = new char [size]; shapefilef.seekg(0,ios::beg); shapefilef.read(data,size); istream shapefile(data);
Where is the mistake? I can't compile it... Something in constructor. -
Thanks a lot!!! Now i want to read the file into the memory and work with this memory like i worke as with file, i think using istream, but i can't make the istream object... Here is my code:
ifstream shapefilef(ShapeFileName.c_str(),ios::binary); shapefilef.seekg(0,ios::end); streampos ps = shapefilef.tellg(); int size = ps.seekpos(); char* data = new char [size]; shapefilef.seekg(0,ios::beg); shapefilef.read(data,size); istream shapefile(data);
Where is the mistake? I can't compile it... Something in constructor.