1.纯C函数, 加windows创建目录函数CreateDirectory
char Buffer[256];
char buf[256];
char b[3];
char* p;
sprintf(b,"//");
sprintf(Buffer,dd);
p = Buffer;
while(strchr(p,'//'))
{
if (p[0] == b[0])
{
int res = p - Buffer + 1;
for(int i = 0; i < res; i++)
buf[i] = Buffer[i];
buf[i] = '/0';
CreateDirectory(buf,NULL);
}
p++;
}
char buf[256];
char b[3];
char* p;
sprintf(b,"//");
sprintf(Buffer,dd);
p = Buffer;
while(strchr(p,'//'))
{
if (p[0] == b[0])
{
int res = p - Buffer + 1;
for(int i = 0; i < res; i++)
buf[i] = Buffer[i];
buf[i] = '/0';
CreateDirectory(buf,NULL);
}
p++;
}
2.C++标准库string, 加windows创建目录函数CreateDirectory
string strPath = szDir;
string strDir = "";
int nPos = 0;
string strPath = szDir;
string strDir = "";
int nPos = 0;
nPos = strPath.find('//',nPos); //返回绝对位置,而不是从npos开始的相对位置
while(nPos != string::npos)
{
strDir = strPath.substr(0, nPos+1);
CreateDirectory(strDir.c_str(), NULL);
while(nPos != string::npos)
{
strDir = strPath.substr(0, nPos+1);
CreateDirectory(strDir.c_str(), NULL);
nPos = strPath.find('//',nPos+1); //此处从‘/’后开始查询
} while(nPos != string::npos);