-1

It's a simple program for version numbers directories. It fails to compile with this error:

no suitable conversion function from "std::string" to "const char *" exists

#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);
            }
        }
    }
}
Bill Lynch
  • 80,138
  • 16
  • 128
  • 173

1 Answers1

6

mkdir() is from the POSIX API, which expects the C language, so it expects a c-style string. So use mkdir(dir.c_str());

If you want to use a C++ API and you have a recent compiler, you could use std::filesystem::create_directory(dir);.

Bill Lynch
  • 80,138
  • 16
  • 128
  • 173