File Path

I need a code to find the path of a file that the folder is in. Doesn't the
__LINE__ give you the
C:\Users\CPlusPlus\Desktop\CPlusPlusDemos\C++.cpp
, but how do you get just the folder path?

You mean __FILE__.
See http://www.cplusplus.com/reference/string/string/find_last_of/ and the example in particular.

But I hope you realize that __FILE__ will give you the path to the current source file at the time of compilation - it has nothing to do with the path the executable is run from.
Use PathRemoveFileSpec() WinAPI to extract folder path from full path.
Can you show me an example of it?
1
2
3
4
#include <shlwapi.lib>

TCHAR path[] = _T("C:\Users\CPlusPlus\Desktop\CPlusPlusDemos\C++.cpp");
PathRemoveFileSpec(path); // path will now contains C:\Users\CPlusPlus\Desktop\CPlusPlusDemos 
Thanks. Just a couple things please. Can you explain the #include <shlwapi.lib> , and what's TCHAR?
There is a typo,should be 'shlwapi.h'.
TCHAR is a macro that resolves to char or wchar_t, depending on UNICODE is defined or not
Topic archived. No new replies allowed.