这是一个用于版本号目录的简单程序。它无法编译,出现此错误:
不存在从“std::string”到“const char *”的合适转换函数
#include <iostream>
#include <stdio.h>
#include <io.h>
using namespace std;
int main() {
int max = 10, daily_patch = 0, monthly_patch = 0, yearly_patch;
cout << " Enter the yearly_patch Number : ";
cin >> yearly_patch;
for (int i = yearly_patch; i <= yearly_patch; i++) {
for (int j = 0; j < max; j++) {
for (int k = 0; k < max; k++) {
string str1 = to_string(i);
string str2 = to_string(j);
string str3 = to_string(k)
string dot = ".";
string dir = str1 + dot + str2 + dot + str3;
mkdir(dir);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
mkdir()来自 POSIX API,它需要 C 语言,所以它需要一个 c 样式的字符串。所以用mkdir(dir.c_str());
如果你想使用 C++ API 并且你有一个最新的编译器,你可以使用std::filesystem::create_directory(dir);.