Share via


編譯器警告 (層級 1) C4905

寬字串常值轉換成 'LPSTR'

編譯器偵測到不安全的轉換。 轉換確實成功,但您應該使用轉換常式。

此警告預設為關閉。 如需詳細資訊,請參閱 預設為關閉的編譯器警告

範例

下列範例會產生 C4905。

// C4905.cpp
// compile with: /W1
#pragma warning(default : 4905)
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>

int main()
{
    LPSTR y = (LPSTR)L"1234";   // C4905

    // try the following lines instead
    // wchar_t y[128];
    // size_t  sizeOfConverted;
    // errcode err = 0;
    //
    // err = mbstowcs_s(&sizeOfConverted, &y[0], 128, "12345", 4);
    // if (err != 0)
    // {
    //     printf_s("mbstowcs_s failed!");
    //     exit (-1);
    // }
    // wprintf(L"%s\n", y);

    return 0;
}