std::stringcharベースのデータを保持するクラスです。std::stringAPI関数にデータを渡すには、そのc_str()メソッドを使用しchar*て、文字列の実際のデータへのポインタを取得する必要があります。
CreateDirectory()入力としてを取りTCHAR*ます。UNICODEが定義されている場合はにTCHARマップされwchar_t、そうでない場合はchar代わりににマップされます。固執する必要があるstd::stringが、コードを認識させたくない場合は、代わりに次のようにUNICODE使用します。CreateDirectoryA()
#include "stdafx.h"
#include <string>
#include <windows.h>
int main()
{
std::string FilePath = "C:\\Documents and Settings\\whatever";
CreateDirectoryA(FilePath.c_str(), NULL);
return 0;
}
このコードをTCHAR認識させるには、代わりに次のようにします。
#include "stdafx.h"
#include <string>
#include <windows.h>
int main()
{
std::basic_string<TCHAR> FilePath = TEXT("C:\\Documents and Settings\\whatever");
CreateDirectory(FilePath.c_str(), NULL);
return 0;
}
ただし、AnsiベースのOSバージョンは古くからあり、現在はすべてUnicodeです。 TCHAR新しいコードではもう使用しないでください:
#include "stdafx.h"
#include <string>
#include <windows.h>
int main()
{
std::wstring FilePath = L"C:\\Documents and Settings\\whatever";
CreateDirectoryW(FilePath.c_str(), NULL);
return 0;
}