'' : cannot convert from 'int' to 'CString'
该代码是用Visual Studio 2003编写的,但现在我在2008年对其进行了编译。
1 2 3 4 5 6 7 | int AFXAPI AfxMessageBox(LPCTSTR lpszText, UINT nType = MB_OK, UINT nIDHelp = 0); if(iiRecd == SOCKET_ERROR || iiRecd == 0) { iErr = ::GetLastError(); AfxMessageBox(CString(iErr)); goto PreReturnCleanup; } |
在2003年,它运行良好,但是在2008年,它显示了一个错误:
Error 50 error C2440: '
' : cannot convert from 'int' to 'CString'
这个错误是什么意思?
如果没有任何信息(例如错误的代码以及您想在此做什么),则很难提供帮助。
这是一个猜测:
您想要以某种方式将
1 2 | int i = 42; CString str = (CString)i; |
如果您使用的是MFC / ATL CString,则可以尝试以下操作
1 2 3 | int i = 42; CString str; str.Format("%d", i); |
CString :: Format采用
编辑
我在下面将您的评论解释为导致错误的代码。 不过,在文本和解释周围加上一点会很好。
1 2 3 4 5 | if(iiRecd == SOCKET_ERROR || iiRecd == 0) { iErr = ::GetLastError(); AfxMessageBox(CString(iErr)); goto PreReturnCleanup; } |
尝试将其更改为
1 2 3 4 5 6 7 | if(iiRecd == SOCKET_ERROR || iiRecd == 0) { iErr = ::GetLastError(); CString msg; msg.Format("%d", iErr); AfxMessageBox(msg); goto PreReturnCleanup; } |
关于
显然,这是因为您使用了