how to specific the path of _wfopen?

how to specific the path of _wfopen?

i want to open a file in C:\Programs File\Success\expt\happy.rff

_wfopen(handle, "happy", "r")

where is the path parameter?

thanks
Last edited on
_wfopen is the wide version of fopen (in Microsoft C/C++), as such the strings are wide. The path is as you specified.

So to open your file, you'd specify:
_wfopen(L"C:\\Programs File\\Success\\expt\\happy.rff", L"r");
The filename parameter is actually the full path. If you don't specifiy a full path it uses the current directory.

Also note: _wfopen is for wide strings, which you don't appear to be using, and it only takes 2 parameters, not 3:

1
2
3
4
5
FILE* yourfile = _wfopen( L"C:\\Programs File\\Success\\expt\\happy.rff", L"r");
if(!yourfile)
{
  // file failed to open
}


Notice that wide strings are prefixed with the L character.

Also note that _wfopen is MS specific and is not portable. Since you don't appear to need wide character strings, you could probably just use fopen, which is a standard function and is therefore portable:

 
FILE* yourfile = fopen( "C:\\Programs File\\Success\\expt\\happy.rff", "r" );



EDIT: man I've just been a minute too slow today XD
Last edited on
Disch, it's just one of those days.
thanks all of your rely~ ~


If you don't specifiy a full path it uses the current directory.


thoes code will run be different user, the installation directory of program may not same,

so i want to ask how to get the current working directory ,

and how to open the upper folder file of current directory,

for upper folder, I MEANS:

C:\Programs File\Success\expt

is an upper folder of
C:\Programs File\Success\expt\ libraries(current directory)

thanks again


Last edited on


you could probably just use fopen, which is a standard function and is therefore portable


i have read msdn of this 4 function , but still don't understand:

when should i use _wfopen?
when should i use fopen?
when should i use fopen_s?
when should i use _wfopen_s?

and i want to ask
do char in C++ is 1 word, more than one word can not be char, right?
thanks
Last edited on
fopen is the ANSI C standard function for opening a file.

_wfopen is the Windows equivalent that supports wide string. Wide strings are native on the WIN32 API. char strings are converted to/from during use. So this is a WIN32 specific function.

fopen_s is the "safe" version of fopen, introduced by Microsoft in Visual Studio 2005. It's a WIN32 specific function.

_wfopen_s is the "safe" version of _wfopen, introduced by Microsoft in Visual Studio 2005. It's a WIN32 specific function.

Topic archived. No new replies allowed.