^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
data: 20180803
----------------------------------------------新建文件夹----------------------------------------------
>. 调用Windows AP的接口函数
包含头文件:#include <windows.h>
1. CreateDirectory()
#include <windows.h> #include <iostream> int main() { std::string path = "E:\\excel1"; bool flag = CreateDirectory(path.c_str(), NULL); return 0; }
error:c2664 无法将参数1从const char *转换为LPCWSTR;(win32 平台下)
解决方法:
1. 切换到x64平台;或者:
2. 由于vs2013项目默认使用的字符集位unicode,把项目属性页 -> 常规 -> 字符集改为“使用多字符集”

________________________________
C++ 从char *转换到LPCWSTR:
可以使用宏_TEXT("quote")的方法进行转换,如:
LPCWSTR lpszPath = __TEXT("E:\\xia\\"); // or TEXT("E:\\xia");
(使用LPCTSTR lpsz = L("E:\\xia");)
那么char * <--> LPCTSTR 呢?
>. char * 转换为 LPCTSTR
#include <windows.h>
#include <iostream>
int main()
{
// char * to LPCTSTR
char ch[100] = "xiawuhao2013";
int num = MultiByteToWideChar(0, 0, ch, -1, NULL, 0);
wchar_t *wch = new wchar_t[num];
MultiByteToWideChar(0, 0, ch, -1, wch, num);
std::cout << wch << std::endl;
delete []wch;
// LPCTSTR to char *
wchar_t wch1[100] = L"xiawuhao2013";
int num1 = WideCharToMultiByte(CP_OEMCP, NULL, wch1, -1, NULL, 0, NULL, FALSE);
char *ch1 = new char[num1];
WideCharToMultiByte(CP_OEMCP, NULL, wch1, -1, ch1, num, NULL, FALSE);
std::cout << ch1 << std::endl;
delete []ch1;
system("pause");
return 0;
}
配置属性无论是Unicode还是多字符集,输出的结果都如下:

_______________________________
>. 调用C运行库函数,如:int _mkdir()
包含头文件:#include <direct.h>
#include <direct.h>
#include <iostream>
int main()
{
std::string str_path = "E:\\xia";
_mkdir(str_path.c_str()); // 使用mkdir()会有c
return 0;
}
>. 调用system命令,如:md
#include <iostream>
int main()
{
system("md E:\\xia");
return 0;
}
浙公网安备 33010602011771号