我想从 GetModuleFileNameW
中提取路径,然后将 "\hello.dll"
附加到它(不使 "\\\\"
)。怎么做? (我不擅长 Unicode 函数)
最佳答案
假设您确实正在使用路径,请使用 PathAppendW
功能。请注意,您可以通过附加 "hello.dll"
来完成此操作 - 如果 PathAppendW
需要,将添加反斜杠。
或者,您可以非常轻松地编写自己的函数。这是我在 5 分钟内用 std::wstring
s
std::wstring PathAppend(const std::wstring& lhs, const std::wstring& rhs)
{
if (lhs.empty())
{
return rhs;
}
else if (rhs.empty())
{
return lhs;
}
std::wstring result(lhs);
if (*lhs.rbegin() == L'\\')
{
result.append(rhs.begin() + (rhs[0] == L'\\'), rhs.end());
}
else
{
if (rhs[0] != L'\\')
{
result.push_back(L'\\');
}
result.append(rhs);
}
return result;
}
关于c - 如何使用 wchar_t* 在 C 中提取和附加路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7264482/