更新:2007 年 11 月
错误消息
宽字符串强制转换为“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;
}