C++ 实用小技巧
一、错误日志
获取异常所在函数及行数:
cout <<"Error in " << __FILE__ << ": " << __FUNCDNAME__ << " line: " << __LINE__<<endl;
二、程序运行时间
#include <ctime>
clock_t start = clock();
clock_t end = clock();
cout<<"Cost time: "<<(double)(end - start) / CLOCKS_PER_SEC<<endl;
三、protected与private:
private:只有当前类的成员函数能访问?
protected:派生类的成员函数能访问基类的保护成员不能访问基类的私有成员。