error C2664: “void ATL::CStringT::Format(const wchar_t *,...)”: 不能將

error C2664: “void ATL::CStringT::Format(const wchar_t *,...)”: 不能將

error C2664: “void ATL::CStringT<BaseType,StringTraits>::Format(const wchar_t *,...)”: 不能將參數

//==============使用CString類,需包含以下頭文件=====CString類是MFC中的類==============================
#include "string"
#include "afx.h"
//所在CString類,只要是在MFC項目中,均可使用CString類。
//=================================================

error C2664: “void ATL::CStringT<BaseType,StringTraits>::Format(const wchar_t *,...)”: 不能將參數 1 從“const char [11]”轉換爲“const wchar_t *”
報錯代碼:
int k=m_grid.GetItemCount();
//CString str_totalcount=L"總共:"+(CString)(k)+"行";
str_totalcount.Format("總共:%d行",k);
修正之後:
int k=m_grid.GetItemCount();
//CString str_totalcount=L"總共:"+(CString)(k)+"行";
str_totalcount.Format(_T("總共:%d行"),k);
//===================================================
在VC 6.0或者VC++2003中的代碼運行正常,現在用2005運行程序出了錯誤,MouseDemoView.cpp
e:\c++.net\hwl\mousedemo\mousedemo\mousedemoview.cpp(109) : error C2664: “void ATL::CStringT<BaseType,StringTraits>::Format(const wchar_t *,...)”: 不能將參數 1 從“const char [26]”轉換爲“const wchar_t *”
with
[
BaseType=wchar_t,
StringTraits=StrTraitMFC_DLL<wchar_t>
]
與指向的類型無關;轉換要求 reinterpret_cast、C 樣式轉換或函數樣式轉換
e:\c++.net\hwl\mousedemo\mousedemo\mousedemoview.cpp(121) : error C2664: “void ATL::CStringT<BaseType,StringTraits>::Format(const wchar_t *,...)”: 不能將參數 1 從“const char [26]”轉換爲“const wchar_t *”
with
[
BaseType=wchar_t,
StringTraits=StrTraitMFC_DLL<wchar_t>
]
與指向的類型無關;轉換要求 reinterpret_cast、C 樣式轉換或函數樣式轉換
e:\c++.net\hwl\mousedemo\mousedemo\mousedemoview.cpp(132) : error C2039: “formt”: 不是“ATL::CStringT<BaseType,StringTraits>”的成員
with
[
BaseType=wchar_t,
StringTraits=StrTraitMFC_DLL<wchar_t>
]
生成日誌保存在“file://e:\C++.net\hwl\mousedemo\mousedemo\Debug\BuildLog.htm”
這個轉換問題怎麼解決,希望各位說一下
UNICODE轉換問題,在VC2005中主要使用UNICODE編碼,需要這樣寫:
strMemStat.Format(_T("%d"), 255);
在UNICODE或者ASCII編碼都能使用。
所以在VS2005 或者VS2008中,遇到一些輸出等函數時,可能需要在前面加入一些符號
比如有:_T或者TEXT等等
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章