C++ 中的 IncludeTrailingPathDelimiter() 怎么样?
How is IncludeTrailingPathDelimiter() in C++?
是否有类似于 Delphi 的 IncludeTrailingPathDelimiter()
函数的功能,可以将 '\'
字符添加到路径字符串的末尾,而无需在其中写入文字 "\"
我的 .cpp
文件,或我项目的任何其他地方?
#include <shlobj.h>
TCHAR szFolderPath[MAX_PATH];
if (SHGetSpecialFolderPath(NULL, szFolderPath, CSIDL_LOCAL_APPDATA, FALSE))
{
cout << szFolderPath << endl;
}
在 Windows 上,有 Shell API 的 PathCchAddBackslash()
function (it is safer to use than PathAddBackslash()
)。
#include <shlobj.h>
#include <Pathcch.h>
TCHAR szFolderPath[MAX_PATH];
if (SHGetSpecialFolderPath(NULL, szFolderPath, CSIDL_LOCAL_APPDATA, FALSE))
{
PathCchAddBackslash(szFolderPath, MAX_PATH);
cout << szFolderPath << endl;
}
否则,用 C++ 自己实现应该不难。
是否有类似于 Delphi 的 IncludeTrailingPathDelimiter()
函数的功能,可以将 '\'
字符添加到路径字符串的末尾,而无需在其中写入文字 "\"
我的 .cpp
文件,或我项目的任何其他地方?
#include <shlobj.h>
TCHAR szFolderPath[MAX_PATH];
if (SHGetSpecialFolderPath(NULL, szFolderPath, CSIDL_LOCAL_APPDATA, FALSE))
{
cout << szFolderPath << endl;
}
在 Windows 上,有 Shell API 的 PathCchAddBackslash()
function (it is safer to use than PathAddBackslash()
)。
#include <shlobj.h>
#include <Pathcch.h>
TCHAR szFolderPath[MAX_PATH];
if (SHGetSpecialFolderPath(NULL, szFolderPath, CSIDL_LOCAL_APPDATA, FALSE))
{
PathCchAddBackslash(szFolderPath, MAX_PATH);
cout << szFolderPath << endl;
}
否则,用 C++ 自己实现应该不难。