#include "stdafx.h"
#include <string>
#include <windows.h>
using namespace std;
int main()
{
string FilePath = "C:\\Documents and Settings\\whatever";
CreateDirectory(FilePath, NULL);
return 0;
}
Error: error C2664: 'CreateDirectory' : cannot convert parameter 1 from 'const char *' to 'LPCTSTR'
- How do I make this conversion?
- The next step is to set today's date as a string or char and concatenate it with the filepath. Will this change how I do step 1?
- I am terrible at data types and conversions, is there a good explanation for 5 year olds out there?
std::stringis a class that holdschar-based data. To pass astd::stringdata to API functions, you have to use itsc_str()method to get achar*pointer to the string's actual data.CreateDirectory()takes aTCHAR*as input. IfUNICODEis defined,TCHARmaps towchar_t, otherwise it maps tocharinstead. If you need to stick withstd::stringbut do not want to make your codeUNICODE-aware, then useCreateDirectoryA()instead, eg:To make this code
TCHAR-aware, you can do this instead:However, Ansi-based OS versions are long dead, everything is Unicode nowadays.
TCHARshould not be used in new code anymore: