如何使用 OutputDebugString 添加指针
How to use OutputDebugString to add pointer
我有调试模式下的代码:
OutputDebugString(_T("Element Name = ") + (Node->getParentElement() == NULL ? "null" : Node->getParentElement()->getName()) + _T("n"));
//getname() type is CString and GetParentElement() type is CXMLElement
使用此代码,我得到以下错误:错误 C2110:"+":无法添加两个指针。我知道不能添加两个指针。
我应该使用什么 API 来清除此错误?
您可以按如下方式使用它:
TCHAR msgbuf[256]; //keep required size
sprintf(msgbuf, "The value is %sn", charPtrVariable);
OutputDebugString(msgbuf);
由于问题被标记为 C++
,我建议使用 stringstream:
#include <sstream>
//...
std::stringstream ss;
ss << "Element Name = "
<< (Node->getParentElement() == NULL ? "null" : Node->getParentElement()->getName())
<< std::endl;
OutputDebugString(ss.str().c_str());
由于不能将两个指针相加以连接字符串,因此可以使用临时CString
对象并追加到该对象:
CString tmp = _T("Element Name = ");
tmp += Node->getParentElement() == NULL ? "null" : Node->getParentElement()->getName();
tmp += _T("n");
OutputDebugString(tmp);
相关文章:
- 是否允许向空指针添加零?
- 将指向结构数组的指针添加到 std::map
- 将 char* 推送到矢量时出现问题,但在每次迭代后,它会将指向相同值缓冲区的指针添加到矢量中
- 将对象指针添加到向量后的值更改
- 将指针添加到成员对象中的指针动态阵列
- 需要一些关于使用指针添加C++数组的建议
- 如何将函数指针添加到现有va_list
- 为什么对象属性的值在 c++ 中将其指针添加到映射后返回零
- 将对象指针添加到位于类内部的指向对象的指针向量
- 无法将对象上的指针添加到集合
- 将指针添加到不同命名空间中的类时出错
- 向无符号字符指针添加短int
- Delphi中的类型转换指针添加
- 如何将节点指针添加到矢量指针
- 我可以向数组指针添加元素吗
- 向指针添加"const"可以帮助优化吗?
- 向函数指针添加constness时会发生什么
- 向指针添加偏移量
- 为什么使用std::next而不是向指针添加整数
- 无法将指针添加到类指针向量数组