CDebug--MFC调试输出程序

CDebug--MFC调试输出程序

说明

本人原先是使用Qt做C++开发的,但是由于最近相关的工作比较难找,所以找的工作是做MFC的相关开发的,但是MFC中的一些调试程序实在是难用,所以按照Qt对应的程序做了一定的修改操作,参照的程序为Qt的QDebug,使用输出符号进行数据的输出。

源码

//CDebug.h
#pragma once
#include <string>
#include <cstring>
constexpr auto Cendl = "\r\n";
using namespace std;
class CDebug  
{
public:CDebug();
	   //此处只能定义成友元函数,重载友元函数,增强其参数兼容性
	   CDebug & operator<<(const string &str);     //兼容string,char*
	   CDebug & operator<<(const CString &str);   //兼容CString
	   CDebug & operator<<(const int &number);     //兼容int
	   CDebug & operator<<(const unsigned int &number);     //兼容 unsigned int
	   CDebug & operator<<(const long &number);     //兼容 long int
	   CDebug & operator<<(const long long &number);     //兼容 long long int
	   CDebug & operator<<(const float &number);     //兼容float
	   CDebug & operator<<(const double &number);     //兼容double
	   CDebug & operator<<(const long double &number);     //兼容double
	   CDebug & operator<<(const char &number);     //兼容char,一个字符,以字符形式输出   
};
//CDebug.cpp
#include "pch.h"
#include "CDebug.h"

CDebug::CDebug()
{
	//不需要初始化任何的参数信息
}
CDebug & CDebug::operator<<(const string & str)
{
	// TODO: 在此处插入 return 语句
	OutputDebugString(CString(str.c_str()));   //转换为CString,方便使用OutputDebugString输出
	return *this; //返回Debug,为后续接上<<做准备
}

CDebug & CDebug::operator<<(const CString & str)
{
	// TODO: 在此处插入 return 语句
	OutputDebugString(str);
	return *this;
}

CDebug & CDebug::operator<<(const int & number)
{
	// TODO: 在此处插入 return 语句
	CString str;
	str.Format(_T("%d"), number);
	OutputDebugString(str);
	return *this;
}

CDebug & CDebug::operator<<(const unsigned int & number)
{
	// TODO: 在此处插入 return 语句
	CString str;
	str.Format(_T("%u"), number);
	OutputDebugString(str);
	return *this;
}

CDebug & CDebug::operator<<(const long & number)
{
	// TODO: 在此处插入 return 语句
	CString str;
	str.Format(_T("%ld"), number);
	OutputDebugString(str);
	return *this;
}

CDebug & CDebug::operator<<(const long long & number)
{
	// TODO: 在此处插入 return 语句
	CString str;
	str.Format(_T("%lld"), number);
	OutputDebugString(str);
	return *this;
}

CDebug & CDebug::operator<<(const float & number)
{
	// TODO: 在此处插入 return 语句
	CString str;
	str.Format(_T("%f"), number);
	OutputDebugString(str);
	return *this;
}

CDebug & operator<<(CDebug & debug, const double & number)
{
	// TODO: 在此处插入 return 语句
	CString str;
	str.Format(_T("%lf"), number);
	OutputDebugString(str);
	return debug;
}

CDebug & CDebug::operator<<(const long double & number)
{
	// TODO: 在此处插入 return 语句
	CString str;
	str.Format(_T("%lf"), number);
	OutputDebugString(str);
	return *this;
}

CDebug & CDebug::operator<<( const char & number)
{
	// TODO: 在此处插入 return 语句
	CString str;
	str.Format(_T("%c"), number);
	OutputDebugString(str);
	return *this;
}

使用

CDebug()<<123<<"abc"<<1.004<<Cendl;
//或者
CDebug debug;
debug<<"123"<<234<<10-3.1415926<<Cendl;

修改说明

该部分程序仅实现类似于QDebug的功能,目前只支持一些常用的数据格式实现数据输入和输出,一些自定义格式还需要自行添加友元函数或者重写。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值