C++ CreateDirectory函数没有';行不通

C++ CreateDirectory函数没有';行不通,c++,windows,winapi,C++,Windows,Winapi,我正在尝试使用CreateDirectory函数创建一个目录。但它似乎不像我预期的那样有效。我的功能有什么问题 #include "stdafx.h" #include<windows.h> int _tmain(int argc, _TCHAR* argv[]) { wchar_t *path = L"C:\\Users\TempFolder"; CreateDirectory ( path , NULL); return 0; } #包括“stdafx

我正在尝试使用CreateDirectory函数创建一个目录。但它似乎不像我预期的那样有效。我的功能有什么问题

#include "stdafx.h"
#include<windows.h>

int _tmain(int argc, _TCHAR* argv[])
{
    wchar_t *path = L"C:\\Users\TempFolder";
    CreateDirectory ( path , NULL);
    return 0;
}
#包括“stdafx.h”
#包括
int _tmain(int argc,_TCHAR*argv[]
{
wchar_t*path=L“C:\\Users\TempFolder”;
CreateDirectory(路径,空);
返回0;
}

您需要在其中添加另一个反斜杠:

L"C:\\Users\\TempFolder"

并确保以管理员身份运行程序(.exe)。您需要具有管理员权限才能在C:\Users中创建文件夹。

事实上,只要停止在该目录中创建文件夹,它不是您的,系统拥有它。因为这个问题被标记,另一个选项是使用raw:
LR“C:\windows\temp\TempFolder”
@IInspectable:C++11中添加了原始字符串文字。@RemyLebeau:正确。Visual Studio 2013及更高版本支持原始字符串文字。@IInspectable:我的观点是并非所有人都使用VS2013+或C++11作为开头。您没有检查错误。那是Win32 101。请跟我重复,我承诺在调用Win32 API函数时检查错误,我承诺在调用Win32 API函数时检查错误,我承诺在调用Win32 API函数时检查错误,…可能重复我承诺在调用Win32 API函数时检查错误,我保证在调用Win32 API函数时检查错误,我保证在调用Win32 API函数时检查错误,;):D非常感谢