#include <iostream> #define __GEN_STRING_IMPL(x) #x #define __GEN_STRING(x) __GEN_STRING_IMPL(x) #define __GEN_LOCATION_STRING() __FILE__ "(" __GEN_STRING(__LINE__) "):" class CTestObject { public: void print1() { #pragma message(__GEN_LOCATION_STRING() "Add code in function:" __FUNCTION__) } void print2() { #pragma message(__GEN_LOCATION_STRING() "Add code in function:" __FUNCTION__) } }; int main() { std::cout << "Hello World!\n"; }
如这个代码所示,只要在编译时,在输出窗口中将会输出代码路径和对应的信息,双击该信息即可跳转到对应位置(Visual Studio 2022有效)。可以根据需要添加其它信息。也可以根据对应的IDE,对具体格式进行对应的修改。
1>ConsoleApplication36.cpp 1>F:\Projects\ConsoleApplication36\ConsoleApplication36.cpp(12):Add code in function:CTestObject::print1 1>F:\Projects\ConsoleApplication36\ConsoleApplication36.cpp(17):Add code in function:CTestObject::print2 1>ConsoleApplication36.vcxproj -> F:\Projects\ConsoleApplication36\x64\Debug\ConsoleApplication36.exe
标签:__,code,STRING,C++,Add,ConsoleApplication36,pragma,message,GEN From: https://www.cnblogs.com/bodong/p/18154397