下拉刷新
项目详情
navbar_avatar分享
repo_avatar
HelloGitHub 评分
0 人评分
打日志是 C++ 开发中必不可少的一种 debug 方式
开源MIT
认领
收藏
分享
3.2k
星数
中文
C++
主语言
活跃
14
贡献者
10
Issues
组织
0.5.1
最新版本
271
Forks
MIT
协议
更多
dbg-macro image
打日志是 C++ 开发中必不可少的一种 debug 方式,[dbg-macro](https://github.com/sharkdp/dbg-macro) 受 [rust-lang](https://www.rust-lang.org) 中 的 [dbg](https://doc.rust-lang.org/std/macro.dbg.html) 启发,提供比 printf 和 std::cout 更好的宏函数。主要有如下特点: - 美观的彩色输出(当输出不是交互式终端时,颜色将自动禁用) - 兼容 C++11,并且是 header-only - 支持基础类型和 STL 容器类型的输出 - 除了基本信息外,还输出变量名和类型 - 启用 DBG_MACRO_DISABLE 生成 release 版 ```c++ #include <vector> #include <dbg.h> // You can use "dbg(..)" in expressions: int factorial(int n) { if (dbg(n <= 1)) { return dbg(1); } else { return dbg(n * factorial(n - 1)); } } int main() { std::string message = "hello"; dbg(message); // [example.cpp:15 (main)] message = "hello" (std::string) const int a = 2; const int b = dbg(3 * a) + 1; // [example.cpp:18 (main)] 3 * a = 6 (int) std::vector<int> numbers{b, 13, 42}; dbg(numbers); // [example.cpp:21 (main)] numbers = {7, 13, 42} (size: 3) (std::vector<int>) dbg("this line is executed"); // [example.cpp:23 (main)] this line is executed factorial(4); return 0; } ```
收录于:
第 43 期

评论

评分:
暂无精选评论