Incompatible with parameter of type “LPCWSTR”

后端 未结 5 625
终归单人心
终归单人心 2020-12-08 03:42
#include \"stdafx.h\"
#include 
#include 
#include 
#include 
using namespace std;

class Dir
{
public:
         


        
相关标签:
5条回答
  • 2020-12-08 03:43

    you can use wchar_t

    class Dir
    {
    public:
        wchar_t* cat;
    Dir()
    {
        wcout << "(C:/*)\n";
        cat = new wchar_t[50];
        wcin >> cat;
    }
    
        void virtual ShowFiles()
        {
        }
    
    };
    

    In Visual Studio 2013 and later, the MFC libraries for multi-byle character encoding (MBCS) will be provided as an add-on to Visual Studio

    0 讨论(0)
  • 2020-12-08 03:49

    It will work for any settings:

    #include <tchar.h>
    
    MessageBox(NULL, _T("Dialog creation failed! Aborting.."), _T("Error"), MB_OK);
    
    0 讨论(0)
  • 2020-12-08 03:52

    Another way to come by this issue, is to use the Lmacro in front of your string.

    MessageBox(NULL, L"Dialog creation failed! Aborting..", L"Error", MB_OK);
    

    See: What does the 'L' in front a string mean in C++?

    or

    L prefix for strings in C++

    0 讨论(0)
  • 2020-12-08 03:54

    I actually found another way to resolve this error since above method did not work for me.

    I casted all my constant character strings with (LPCWSTR). The solution looks like this
    Earlier

    MessageBox(NULL,"Dialog creation failed! Aborting..", "Error", MB_OK);
    

    After casting to LPCWSTR

    MessageBox(NULL, (LPCWSTR) "Dialog creation failed! Aborting..", (LPCWSTR) "Error", MB_OK);
    

    So just copying the (LPCWSTR) and pasting wherever this error was generated resolved all my errors.

    0 讨论(0)
  • 2020-12-08 04:08

    To compile your code in Visual C++ you need to use Multi-Byte char WinAPI functions instead of Wide char ones.

    Set Project -> Properties -> General -> Character Set option to Use Multi-Byte Character Set

    0 讨论(0)
提交回复
热议问题