cannot load file into vc++ program.

hi,
i wrote a program that it read a file from the harddisk. but it seem not to be able to load the file. i checked the file name and copy the input file to the debug folder and to the the folder where my source file is, but it still return null. i checked the project property->debug->working directory, and it indicated that it was the macro $(ProjectDir). it should be ok right? if i can not get this right, there would be very bad to the other projects that i want to do. is there a way i can check the content of $(ProjectDir) to see what it is? does anyone has any idea what should i check for?

thanks
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <direct.h>

int main()
{
    // *******************************************
    // **** WARNING **** microsoft specific **** 
    // *******************************************

    char* working_directory = _getcwd( 0, 0 ) ; 
    std::cout << "working_directory: " << working_directory << '\n' ;
    std::free(working_directory) ;
}


Suggestion: Why not just use a fully qualified path to the file? (Perhaps read it from a config file).
hi JLBorges:

i added part of your code into my program. it confirmed that my directory and file name are correctly set, but my program still returned NULL. what i actually trying to do is to read in a TGA file and use it as a texture for my opengl program. i do not understand what do you mean by "read it from a config file"? i tried the full path in my program, it had wiggly underline under the directory. i don't understand what is the problem. i simply copy the output from your code and added it to the beginning of my TGA file name. the wiggly line usually mean the variable is not defined. the path is
"C:\Users\rob\Dev C++ source\MSVC++\freeglut\sin func with texture\Men.tga", with the wiggly underline under Users only. when i deleted the Users, the underline went away.

any suggestion?

thanks
Last edited on
How are you trying to open the file? With std::fopen()? Post that one line of code.
Topic archived. No new replies allowed.