Damn I/O!! ( HELP PLEASE! )

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

fantastico
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 20
Joined: Fri Mar 20, 2009 4:37 am
Location: Germany

Re: Damn I/O!! ( HELP PLEASE! )

Post 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);
User avatar
MadPumpkin
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 484
Joined: Fri Feb 13, 2009 4:48 pm
Current Project: Octopia
Favorite Gaming Platforms: PS1-3, Genesis, Dreamcast, SNES, PC
Programming Language of Choice: C/++,Java,Py,LUA,XML
Location: C:\\United States of America\Utah\West Valley City\Neighborhood\House\Computer Desk

Re: Damn I/O!! ( HELP PLEASE! )

Post 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
While Jesus equipped with angels, the Devil's equipped with cops
For God so loved the world that he blessed the thugs with rock
Image
Image
Image
fantastico
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 20
Joined: Fri Mar 20, 2009 4:37 am
Location: Germany

Re: Damn I/O!! ( HELP PLEASE! )

Post 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.
Post Reply