• Advertisement
Sign in to follow this  

I are dumb. c++ file i/o question

This topic is 4709 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

I seem to have forgotten how to specify file locations when reading in from a file. if my VC++ 6.0 directory looks like this... projectproject\src project\header project\data project\debug in my code, I want to specify that the executable in project\debug read data from the project\data directory, I thought I gave the file name as "..\\data\\filename.dat" but that doesn't seem to work. I've tried every combination I can imagine, but it doesn't seem to work. Any help?

Share this post


Link to post
Share on other sites
Advertisement
You're correct in your understanding, the problem is that relative paths (such as "..\\data\\blah.txt") are relative to the current directory, not the executable's location. VC++ 6.0 uses the project directory, not the Debug directory, as the default executable path.

Share this post


Link to post
Share on other sites
So how do I specify it? I previously thought this might be true, but I also atempted "data\\filename.dat" and "\\data\\filename.dat" thinking it would run from the current directory, but it didn't seem to work still.

Share this post


Link to post
Share on other sites
I would have thought that "data\\filename.dat" would work, given the directory structure you've described. You can check the starting directory for your project by going Alt+F7 (or Project->Settings), selecting the top level node in your project in the tree view at the left, clicking on the 'Debug' tab at the top, and looking at (or changing) the 'Working Directory' field.

Note that anything that you do that sets the working directory (eg. file open dialogs) will make your relative paths break. I usually build full paths using the module filename (GetModuleFileName() iirc) and appending the relative path from my .exe to the file.

PS. where is your workspace (.dsw) file? Also, is the source in "project\project\src" or is that a typo?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement