在 VISUAL STUDIO 中获取错误:错误 C2664:“_chmod”:无法将参数 1 从 'wchar_t [260]' 转换为 'const char *'

GETTING THE ERROR IN VISUAL STUDIO: error C2664: '_chmod' : cannot convert parameter 1 from 'wchar_t [260]' to 'const char *'

用于删除任何文件夹的 C++ 代码:

#include <string>
#include <iostream>
#include "stdafx.h"
#include <stdio.h>
#include <afx.h>
#include <windows.h>
#include <conio.h>
#include <io.h>

using namespace std;

BOOL IsDots(wchar_t* str)
{
    if (_tcscmp(str, TEXT(".")) && _tcscmp(str, TEXT("..")))
        return FALSE;
    return TRUE;
}

BOOL DeleteDirectory(wchar_t* sPath)
{
    HANDLE hFind;
    WIN32_FIND_DATA FindFileData;

    wchar_t DirPath[MAX_PATH];
    wchar_t FileName[MAX_PATH];

    _tcscpy(DirPath, sPath);
    _tcscat(DirPath, TEXT("\*"));
    _tcscpy(FileName, sPath);
    _tcscat(FileName, TEXT("\"));

    //GETTING THE FISRT FILE

    hFind = FindFirstFile(DirPath, &FindFileData);
    if (hFind == INVALID_HANDLE_VALUE)
        return FALSE;
    _tcscpy(DirPath, FileName);

    bool bSearch = true;
    while (bSearch) {
        if (FindNextFile(hFind, &FindFileData)) {

            if (IsDots(FindFileData.cFileName))
                continue;

            _tcscat(FileName, FindFileData.cFileName);
            if ((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {

                //DELETING THE DIRECTORY

                if (!DeleteDirectory(FileName)) {
                    FindClose(hFind);
                    return FALSE;
                }
                RemoveDirectory(FileName);
                _tcscpy(FileName, DirPath);
            }

            else {

                if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
                    _chmod(FileName, _S_IWRITE);
                mode if (!DeleteFile(FileName))
                {
                    FindClose(hFind);
                    return FALSE;
                }

                _tcscpy(FileName, DirPath);
            }
        }

        else {
            if (GetLastError() == ERROR_NO_MORE_FILES)
                bSearch = false;
            else {

                FindClose(hFind);
                return FALSE;
            }
        }
    }
    FindClose(hFind);

    return RemoveDirectory(sPath);
}

//CALLING THE DEL DIR FUNCTION

希望任何人都能提供帮助!!

我收到以下错误:

error C2664: '_chmod' : cannot convert parameter 1 from 'wchar_t [260]' to 'const char *'

P.S。我使用微软 Visual Studio.

您正在使用 宽字符,但调用了 窄字符 版本的函数。

大多数 Windows API 函数 transparently switch between the two by virtue of the UNICODE macro being set. The "chmod" function with this behaviour is _tchmod

你应该切换到_tchmod