【问题标题】:MFC conversion errorMFC 转换错误
【发布时间】:2013-09-03 16:44:40
【问题描述】:

我在我的 MFC DOC/VIEW 应用程序中遇到了一些带有转换 LPCTSTR 参数 (szNewChr) 的错误,错误:错误 C2664: 'int ATL::CStringT::Find(wchar_t,int) throw() const' : cannot convert参数 1 从 'const char [2]' 到 'wchar_t', 在 atof 方法中,出现错误:错误 C2664: 'atof' : cannot convert parameter 1 from 'CString' to 'const char *'

这是我的方法:

void CmojaView::UpdateResultsWnd(LPCTSTR szNewChr)
{
// Ensure we are not trying to add a second decimal point!
if(szNewChr == "." && m_strCurrentEntry.Find(".") != -1)
    return;

// Update the private member variables
m_strCurrentEntry+=szNewChr;
CString strCurrentEntry(m_strCurrentEntry);
strCurrentEntry.Remove('*');
strCurrentEntry.Remove('/');
m_fResultsWndValue=atof(strCurrentEntry);
m_nClearBtnStatus=0;

}

这些是 .h 文件中定义的数据成员:

CString m_strCurrentEntry;      
double m_fResultsWndValue;      
double m_fRunningTotal;         
char m_cLastOp;                 
int m_nClearBtnStatus;          
double m_fMemory;               
UINT m_nLastKey;

我想注意到它可以完美地作为基于对话框的应用程序... 提前致谢。

【问题讨论】:

  • this。它解决了同样的问题。

标签: mfc


【解决方案1】:

我认为这是与多字节和 unicode 有关的问题。从“属性”->“常规”->“字符集”将项目切换到“使用多字节字符集”模式。

如果您仍想使用 Unicode 模式,请将所有常量字符串从 "..." 更改为 _T("..."),将 '*' 更改为 _T('*')。将 atof 更改为 _ttof。

【讨论】:

    猜你喜欢
    • 2014-11-29
    • 2012-05-07
    • 2014-06-29
    • 1970-01-01
    • 1970-01-01
    • 2021-12-20
    • 1970-01-01
    相关资源
    最近更新 更多