Page 2 of 2
Re: Damn I/O!! ( HELP PLEASE! )
Posted: Sat Apr 04, 2009 3:14 pm
by fantastico
MadPumpkin wrote:thank you for all of your help! everybody!! now, fantastico, about the filen.size() is there a way to do that so that i actually get the stream size instead of name of file?
Taken from
http://www.cplusplus.com/reference/iost ... tellg.html :
Code: Select all
is.seekg (0, ios::end);
int length = is.tellg();
is.seekg (0, ios::beg);
Re: Damn I/O!! ( HELP PLEASE! )
Posted: Sat Apr 04, 2009 3:53 pm
by MadPumpkin
fantastico wrote:MadPumpkin wrote:thank you for all of your help! everybody!! now, fantastico, about the filen.size() is there a way to do that so that i actually get the stream size instead of name of file?
Taken from
http://www.cplusplus.com/reference/iost ... tellg.html :
Code: Select all
is.seekg (0, ios::end);
int length = is.tellg();
is.seekg (0, ios::beg);
will this work with what im trying to do? what im trying to do is, make it load the whole file in spite of what its size is
Re: Damn I/O!! ( HELP PLEASE! )
Posted: Sun Apr 05, 2009 3:26 am
by fantastico
Yea it should work like this:
Code: Select all
ifstream is;
is.open("filename", ios::binary);
is.seekg(0, ios::end);
unsigned int length = is.tellg();
is.seekg(0, ios::beg);
char* buffer = new char[length];
is.read(buffer, length);
It should load the whole file into that byte array buffer and I guess it will work as long as the file size fits into that unsigned int and there is enough memory for new to succeed.