天天看點

【VC++】關于 warning C4996: 的解決方法。。

VS2008+SP1  Unicode 環境

使用 wcscpy(Dest,Src);

編譯會出現如下提示:

warning C4996: 'wcscpy': This function or variable may be unsafe. Consider using wcscpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

雖然編譯,運作都正常,但是這個警告看着都不順。。

網上查找了下。。

找到了 如下定義:

#ifdef UNICODE
#define lstrcat  lstrcatW
#else
#define lstrcat  lstrcatA
#endif // !UNICODE  

           

 原來是自适應函數。。根據你的編譯選項選擇的是多位元組還是unicode位元組來自動選擇strcpy還是wcscpy

LPTSTR lstrcpy(      

    LPTSTR lpString1,
    LPTSTR lpString2
); int lstrcmp(      

    LPCTSTR lpString1,
    LPCTSTR lpString2
); int lstrcmpi(      

    LPCTSTR lpString1,
    LPCTSTR lpString2
);LPTSTR lstrcpyn(      

    LPTSTR lpString1,
    LPCTSTR lpString2,
    int iMaxLength
);LPTSTR lstrcat(      

    LPTSTR lpString1,
    LPTSTR lpString2
);
int lstrlen(      

    LPCTSTR lpString
);