• 文件夹操作(转)


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

    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;
    }
    
  • 相关阅读:
    Layer Trees Reflect Different Aspects of the Animation State
    CALayer
    iOS学习笔记09-核心动画CoreAnimation
    CAShapeLayer使用
    iOS动画的要素:CALayer维护数据模型和图片,沟通了CPU和GPU--视图中与图形绘制相关的功能
    CoreAnimation confusion: CATransaction vs CATransition vs CAAnimationGroup?
    圆环,扇形控件基本算法一种实现
    pthread_barrier_init,pthread_barrier_wait简介
    完整详解GCD系列(三)dispatch_group
    GCD学习(五) dispatch_barrier_async
  • 原文地址:https://www.cnblogs.com/xiawuhao2013/p/9412902.html
Copyright © 2020-2023  润新知