error C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
解決方案: 右鍵工程 --> 屬性 --> 預處理器 --> 預處理器宏定義 --> 編輯 --> 輸入 錯誤提示中的 _CRT_SECURE_NO_WARNINGS
參數 --> 應用即可
error C2664 “void ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t>>>::Format(UINT,...)”: 無法將參數 1 從“const char [3]”轉換為“const wchar_t *”
問題分析
VC2005及更高版本默認使用Unicode字符集,CString里存的是寬字符,也就是wchar_t,而不再是char。你可以這么寫:
string.Format(_T("%4d-%2d-%2d"),st.wYear,st.wMonth,st.wDay)
以后寫程序的時候,定義字符串變量,不要用 char*
,而用 TCHAR*
。 所有字符串常量,不要直接用 " "
,而要用 _T("")
。
舉個栗子:
TCHAR* str = _T( "Hello, World" );MessageBox( _T( "Hello" ));
【注】 以上內容是在MFC里面的書寫方式。寫控制臺程序的話,就不用了。原鏈