reading textures filenames

Greetings:

Imagine yourself you´re using lesson06 from NeHes…
somewhere the LoadBMP function is called like this:
LoadBMP(“Data/NeHe.bmp”)

My problem is that my texture filename is stored in data.txt
(content of data.txt)
c:\some hing ext1.bmp
blah
blah
blah
(EOF)

I´ve tried everything string.data(), string.c_str(), char, char* and still can make it work

All I need is to call LoadBMP with some variable that has the texture filename… and make it work!

LoadBMP(var)

And some nice cube with MY texture appears

Hope someone could help me
Thanks

Do you know how to open the file using iostream functions?

have you tried using “istream myFile;” then

myFile.open( “data.txt”)

then use some looping function or procedure to read in the string. Also be sure to write checks for null files, small files and large files. And make sure your program is secure and does not crash (no buffer overflows).

However, what where you having trouble with specifically?

I believe for this cause the istream is the way to go.

#include <fstream>

ifstream myFile;
string fileName;

myFile.open(fileName.c_str());

/* This code will open a file associated with the string fileName, you can then referece the file through the stream!*/

I hope this helps

[This message has been edited by GlutterFly (edited 08-01-2003).]

Then you need a array variable:
would look something like this in C, note just an example some of the functions names maybe not 100% correct.

char Texture_file_list[10][30];
int files, i;

i = 0;

// First read in the file list
file = open(“data.txt”)
while( file != EOF )
{
getstr( file, Texture_file_list[files] );
files++;
}

// Now load the names from the file list
for( i = 0; i < files; i++)
{
LoadBMP( Texture_file_list[i] );
}

Originally posted by Titus:
[b]Greetings:

Imagine yourself you´re using lesson06 from NeHes…
somewhere the LoadBMP function is called like this:
LoadBMP(“Data/NeHe.bmp”)

My problem is that my texture filename is stored in data.txt
(content of data.txt)
c:\some hing ext1.bmp
blah
blah
blah
(EOF)

I´ve tried everything string.data(), string.c_str(), char, char* and still can make it work

All I need is to call LoadBMP with some variable that has the texture filename… and make it work!

LoadBMP(var)

And some nice cube with MY texture appears

Hope someone could help me
Thanks[/b]

Use the “getline” member function of istream to read in the texture names. And make sure your program is secure for all types of possible inputs.

Instead of using arrays of char strings, which are subject to buffer overflow, prefer to use vectors of strings:

#include <vector>
#include <string>

using std::vector;
using std::string;

vector<string> names;

names.push_back(“name1”);
names.push_back(“name2”);

C++ takes care of all the memory allocation/deallocation for you.