c++打印调试定位信息
需求
在没有GLOG可用的前提下使用std::cout
对代码进行简单调试。
解决
使用自带marco可以作为平替,上代码
#include <iostream>
class A
{
public:
void show()
{
std::cout << "This is " << __func__ << std::endl;
}
};
int main()
{
A a;
std::cout << "Compiled at " << __DATE__ << " " << __TIME__ << std::endl;
std::cout << "Start at " << __LINE__ << std::endl;
a.show();
std::cout << "Finish "<< __func__ <<" at " << __LINE__ << std::endl;
return 0;
}
效果
输出结果如下
Compiled at Jul 12 2023 08:49:04
Start at 16
This is show
Finish main at 18