Skip to main content
gamedev.net
🔒 Locked

File reading/writing

Started by Dwarf with Axe 0 replies 150+ views
Original Post
Dwarf with Axe
Dwarf with Axe
Just curious as to how I can go about doing this. I have a limited experience with file handling, and here''s what I''m trying to do: I have a file, textures.dat, that I want to open (It''s a standard text file). First thing I want to do is find out how many lines are in the text file and store that in a variable somewhere. Then, I''m going to want to read all the lines, each in their own buffer, and then close the file. Finally, loop through how many lines there were and create the textures from the buffers. A sample of the textures.dat file would look like this:
TEXTURE 1 "skins/bob/bob.bmp"
TEXTURE 2 "skins/bob/bobs_hat.bmp"
TEXTURE 3 "skins/bob/bobs_foot.bmp"
 
I know how to do everything else; Just the whole ''read the line. if it has something, goto the next line. if _that_ line has something, goto the next line. If any lines have nothing, stop and return the number of lines'' part I cant seem to do. Thanks, ~Dwarf
IndirectX
IndirectX
You can try something like (untested):

  
struct FileEntry
{
std::string type;
int id;
std::string filename;
};

void ReadFile(std::istream& is, std::vector <FileEntry>& v)
{
v.clear();
FileEntry fe;
while (!is.eof())
{
is >> fe.type >> fe.id;
getline(is, fe.filename);
v.push_back(fe);
}
}
---visit #directxdev on afternet <- not just for directx, despite the name

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.