C++のカレントディレクトリにループを使っていくつかのフォルダを作ってみたい。コードを作成しましたが、次のエラーが発生しました。C++のカレントディレクトリ内に複数のフォルダを作成
cannot convert 'std::string {aka std::basic_string}' to 'const char*' for argument '1' to 'void CreateFolder(const char*)'
私のコードは次のとおりです。
#include<iostream>
#include<cstdio>
#include<cstring>
#include <windows.h>
#include <cstdio>
#include<cstdlib>
#include<fstream>
#include <sstream>
using namespace std;
#define total 28
std::string to_string(int i) {
std::stringstream s;
s << i;
return s.str();
}
void CreateFolder(const char * path)
{
if(!CreateDirectory(path ,NULL))
{
return;
}
}
main()
{
string folder_name;
string suffix = ".\\"; // for current directory
for(int i=0;i<=total;i++)
{
folder_name=suffix+to_string(i);
CreateFolder(folder_name);
}
}
は、どのように私は28に... 0,1という名前のこれらのフォルダが作成されますか?
ヒント:文字列または文字リテラルの中でバックスラッシュは何を意味しますか?それについて一瞬考えてみましょう。 –
'CreateFolder(folder_name);'を 'CreateFolder(folder_name.c_str);で置き換え、[' string :: c_str'](http://www.cplusplus.com/reference/string/string/c_str/)を参照してください。方法。 –
この質問のタイトルはまったく間違っています。そして、これはC++とタグ付けされるべきです。それはWINAPIの質問よりもC++の質問のほうが多いです。 –