c++中使用cout创建DebugPrint函数的简单方法

Simple way of DebugPrint function creation with cout in c++

本文关键字:函数 简单 方法 DebugPrint 创建 cout c++      更新时间:2023-10-16

是否有一些简单的方法来创建DebugPrint函数,基于cout,它将接受cout支持的所有数据类型。

我试着

void DebugPrint(void * data)
{
  cout<<data<<endl;
}

使用模板:

template<class T> inline void DebugPrint( const T& data )
{
   cout << data << endl;
}

或宏:

#define DebugPrint( data ) cout << data << endl;

模板总是更可取的…(通常)必须避免使用宏。