#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;
}