我的代码处于调试模式:
OutputDebugString(_T("Element Name = ") + (Node->getParentElement() == NULL ? "null" : Node->getParentElement()->getName()) + _T("\n"));
//getname() type is CString and GetParentElement() type is CXMLElement使用这段代码,我得到下面的错误: error C2110:'+‘:无法添加两个指针。我知道两个指针不能相加。
应该使用什么API来清除此错误?
发布于 2016-03-21 20:04:14
您可以使用它,如下所示:
TCHAR msgbuf[256]; //keep required size
sprintf(msgbuf, "The value is %s\n", charPtrVariable);
OutputDebugString(msgbuf);发布于 2016-03-22 04:45:01
因为问题是用C++标记的,所以我建议使用stringstream:
#include <sstream>
//...
std::stringstream ss;
ss << "Element Name = "
<< (Node->getParentElement() == NULL ? "null" : Node->getParentElement()->getName())
<< std::endl;
OutputDebugString(ss.str().c_str());发布于 2016-03-21 21:00:04
因为不能将两个指针添加到一起来连接字符串,所以可以使用临时CString对象并附加到该对象:
CString tmp = _T("Element Name = ");
tmp += Node->getParentElement() == NULL ? "null" : Node->getParentElement()->getName();
tmp += _T("\n");
OutputDebugString(tmp);https://stackoverflow.com/questions/36130404
复制相似问题