Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

BeanDog

Using Null-Terminating string filenames

This topic is 6940 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Remember how for a long time I was beggin someone to show me a string-input DX-based routine? Well, I made one. If you want it, you can e-mail me at benbeandogdilts@cs.com. Now that I have that working, I have a pointer to this data: level1.bwc''\n''cdsjcpody8sa0432o1;nk, jdosa7f89a jdska;cd which, when I interpret it, just means "level1.bwc". How do I use this data to open up an ofstream or ifstream object? Say my variable is a LPSTR named filename. If the LPSTR points to the above data, and I try to open a file, it doesn''t work for some reason. Should it? Any suggestions? ~BenDilts( void ); Come to my Web Site at www.geocities.com/benbeandogdilts. At my downloads page you will find SQUIRMS V1.02!!! GRAB IT AND TELL ME IF YOU LIKE IT!!! p.s. some reports say it doesn''t work on some systems. Let me know. Bean Dog

Share this post


Link to post
Share on other sites
Advertisement
You are a godsend. I''ve been working on that problem for months. BTW, how do you check if a file exists? For file loads, of course.

Share this post


Link to post
Share on other sites
A simple way:

ifstream file(filename);
if (!file)
{
// It''s not here, or something is wrong.
}

The !operator is overloaded to call the fail() function. Look into the basic_ios::good/eof/fail/bad functions in your docs if you want more detail. Depending on your implementation, you may need an ios::nocreate flag in your file constructor or open() call to stop it making the file if it''s not there. However, I believe this flag is now nonstandard and deprecated.

Share this post


Link to post
Share on other sites
Or, you can look up _access(). That function will tell you if a file exists, and it''s access permission level (read only, etc...)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!