当前位置: 首页 > 工具软件 > makesure > 使用案例 >

c++ 利用MakeSureDirectoryPathExists直接创建多级目录

梁祯
2023-12-01
#include <ImageHlp.h>
#pragma comment(lib,"imagehlp.lib") 


string path = "F:/a\\C/D\\E/我是按法律司法局撒娇时发神经的拉升的农历撒/";

std::cout << path << std::endl;
	
string_replace(path, "/", "\\");
std::cout << path << std::endl;


MakeSureDirectoryPathExists(path.c_str());

//只支持“\\”,而且路径中必须以“\\”结尾,不支持“/”
#include<string>
#include<iostream>
using namespace std;

//第一种替换字符串的方法用replace()

void string_replace(string&s1,const string&s2,const string&s3)
{
	string::size_type pos=0;
	string::size_type a=s2.size();
	string::size_type b=s3.size();
	while((pos=s1.find(s2,pos))!=string::npos)
	{
		s1.replace(pos,a,s3);
		pos+=b;
	}
}

//第二种替换字符串的方法用erase()和insert()

void string_replace_2(string&s1,const string&s2,const string&s3)
{
	string::size_type pos=0;
	string::size_type a=s2.size();
	string::size_type b=s3.size();
	while((pos=s1.find(s2,pos))!=string::npos)
	{
		s1.erase(pos,a);
		s1.insert(pos,s3);
		pos+=b;
	}
}


string path = "F:/a\\C/D\\E/";
std::cout << path << std::endl;
	
string_replace(path, "/", "\\");
std::cout << path << std::endl;




 

 类似资料: