本文主要是介绍打印文件名和文件行调试信息,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#include <iostream>
#include <map>
#include <tuple>
// #include "types.h"
namespace teaflow {// 从 __FILE__ 找到文件的名
constexpr int32_t basename_index(const char * const path, const int32_t index = 0, const int32_t slash_index = -1) {return path[index]? ((path[index] == '/' || path[index] == '\\')? basename_index (path, index + 1, index): basename_index (path, index + 1, slash_index)): (slash_index + 1);
}#define STRINGIZE_DETAIL(x) #x
#define STEINGIZE(x) STRINGIZE_DETAIL(x)#define __FILELINE__ \
(&((__FILE__ ":" STEINGIZE(__LINE__))[basename_index(__FILE__)]))}using namespace teaflow;
int main() {auto k = __FILELINE__;std::cout << k << " file:" << __FILE__ << " "<< basename_index(__FILE__) << std::endl;return 0;
}
输出:
main.cpp:27 file:/Users/wuyongyu/CLionProjects/teaflow_test/main.cpp 43
这篇关于打印文件名和文件行调试信息的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!