zoukankan      html  css  js  c++  java
  • 文件夹操作(转)

    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    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;
    }
    
  • 相关阅读:
    数据库范式 说明
    javascript链式调用实现方式总结
    jQuery工作原理解析以及源代码示例
    jquery 中 (function( window, undefined ) {})(window)写法详解(转)
    jQuery基础---filter()和find()
    使用PHP连接、操纵Memcached的原理和教程
    一篇memcache基础教程
    css书写规范
    可穿戴设备的未来市场
    axure篇
  • 原文地址:https://www.cnblogs.com/xiawuhao2013/p/9412902.html
Copyright © 2011-2022 走看看