(可能将此标记为重复的人:
我看到Convert CString to const char*在使用此宏时会返回sam错误:
CT2A ascii(m_InstrumentName, CP_UTF8);
TRACE(_T("UTF8: %S\n"), ascii.m_psz);
我不知道这是如何运作的
和Problem: How to convert CString into const char * in C++ MFC(它返回错误C2440:'输入':无法从' CString'转换为' LPCSTR')
我有一个代码可以解决这个错误:
错误6错误C2664:' void CElliotEngineDoc :: ExportFile(CFile *,const char *)' :无法转换来自' CString'的参数2 to' const char *'
这不是我的代码,它是用VC 8.0编写的,我使用的是VC 12.0
以下是定义和调用函数的部分。
你能告诉我这会是什么问题吗?
调用的函数:
void CElliotEngineDoc::ExportFile(CFile* fp, const char* isin)
{
CString s = "time;isin;high;low;last;vol$;open\r\n";
fp->Write(s, s.GetLength());
char buf[100];
PriceNodeVec::const_iterator it = m_PriceNodes.begin();
while (it != m_PriceNodes.end())
{
const PriceNode& n = *it++;
sprintf(buf, "%s;%s;%g;%g;%g;%g;%g\r\n",
n.date.Format("%Y%m%d"),
isin,
n.high,
n.low,
n.price,
n.volume,
n.close );
fp->Write(buf, strlen(buf));
} // while
}
这里是CString的定义(如果我没错):
typedef ATL::CStringT< wchar_t, StrTraitMFC_DLL< wchar_t > > CStringW;
typedef ATL::CStringT< char, StrTraitMFC_DLL< char > > CStringA;
typedef ATL::CStringT< TCHAR, StrTraitMFC_DLL< TCHAR > > CString;
m_InstrumentName的定义如下:
CString m_InstrumentName;
错误就在这一行:
ExportFile(ar.GetFile(), m_InstrumentName);