是否有类似于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()
函数(使用它比 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++中自己实现它应该不难。
关于c++ - C++中的IncludeTrailingPathDelimiter()如何?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49310032/