我正在 append wstring。我在 wstring 中有“C:\Windows”。我正在向它 append “\system32\config\”。通过以下代码。
#define MAX_PATH 260
wstring wstrWindowsDirectory;
if(0 != GetWindowsDirectory((LPWSTR)wstrWindowsDirectory.c_str(),MAX_PATH))
{
if(!wstrWindowsDirectory.empty()) {
wstrWindowsDirectory += L"\System32\\config\\";
}
}
But its crashing..
please help me..
Thanks in advance.
最佳答案
当您通过 c_str()
将内容写入字符串时,它不会自动增长。
因此,无法保证 wstrWindowsDirectory
足够大以包含您尝试写入其中的路径。
在调用 GetWindowsDirectory()
之前,您需要使用 wstring::reserve()
。
关于c++ - Windows 中的 Exe 在调用 GetWindowsDirectory 时 append wstring 时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41095639/