vc++创建文件目录
2015-08-24 15:22
627 查看
#include "stdafx.h" #include <iostream> #include <fstream> #include <string> #include <tchar.h> #include<windows.h> using namespace std; LPWSTR StringToLPWSTR(string s) { const char * szString = s.c_str(); int dwLen = strlen(szString) + 1; int nwLen = MultiByteToWideChar(CP_ACP, 0, szString, dwLen, NULL, 0);//算出合适的长度 LPWSTR lpszPath = new WCHAR[dwLen]; MultiByteToWideChar(CP_ACP, 0, szString, dwLen, lpszPath, nwLen); return lpszPath; } int _tmain(int argc, _TCHAR* argv[]) { string file_dir = "d:\\中国1\\中国2\\中国3\\中国4"; string file_name = ""; string file_part_path = file_dir; string file_path; int symbol_index = 0; while (symbol_index != -1) { symbol_index = file_part_path.find("\\"); file_name = file_part_path.substr(0, symbol_index + 1); file_part_path = file_part_path.substr(symbol_index + 1); file_name = symbol_index == -1 ? file_part_path : file_name; file_path += file_name; LPWSTR lp_dest_file_dir = StringToLPWSTR(file_path); CreateDirectoryW(lp_dest_file_dir, NULL); cout << file_path << endl; } system("pause"); return 0; }
相关文章推荐
- C++ Primer 学习笔记_33_STL实践与分析(7) --容器适配器
- 黑马程序员--C语言指针详解
- 关于C语言中二维数组的P+1与*(P+1)个人浅见
- c++程序设计书本P360.5
- 浅析C语言中strtol()函数与strtoul()函数的用法
- C++中指针使用小结
- websocket C/C++服务器应用
- c++11生产者消费者
- C++ 构造函数与析构函数详解(一)---局部变量
- C++虚拟继承与普通继承的区别
- 2016年阿里C/C++开发笔试程序题二
- C语言中对字母进行大小写转换的简单方法
- [LeetCode] Missing Number
- 关于C语言中二维数组的P+1与*(P+1)个人浅见
- C语言strlen函数和sizeof操作符
- POJ 2240 && ZOJ 1082 Arbitrage 最短路,c++ stl pass g++ tle 难度:0
- C++实现红黑树与验证
- VC++6.0重命名Project名称及其MFC工程及类文件名
- 在Eclipse中搭建C/C++环境
- POJ C++程序设计 编程题#1 大整数的加减乘除