我正在尝试打开一个文件处理程序到我从文件中获得的路径,我有输入文件,其中包含完整路径,例如:c:\def\es1.txt
我将“\”字符替换为双“\”,因此它适合字符串格式,然后我正在使用:
myfile = fopen("temp.txt", "r");
while (fgets(line, line_size, myfile) != NULL){
printf("==============================\n");
printf(line);
system("PAUSE\n");
mbstowcs(wtext, line, strlen(line) + 1);//Plus null
_tprintf(wtext);
LPWSTR ptr = wtext;
hFile = CreateFile(wtext, // name of the write
GENERIC_WRITE, // open for writing
0, // do not share
NULL, // default security
OPEN_EXISTING, // create new file only
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
if (hFile == INVALID_HANDLE_VALUE)
{
DisplayError(TEXT("CreateFile"));
_tprintf(TEXT("Terminal failure: Unable to open file \"%s\" for write.\n"), wtext);
return;
}
else {
printf("yes!!!!!!!\n");
}
当命令 _tprintf(wtext); 发生我看到的字符串应该是:“c:\def\es1.txt”
但 CreateFile 命令失败:
FATAL ERROR: Unable to output error code.
ERROR: CreateFile failed with error code 123 as follows:
The filename, directory name, or volume label syntax is incorrect.
Terminal failure: Unable to open file "c:\\def\\es1.txt
" for write.
当我将 CreateFile 中的 wtext 变量替换为:L"c:\\def\\es1.txt"
它工作正常,有什么问题?