Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/145.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;宏中的串联_C++_C Preprocessor_Stringification - Fatal编程技术网

C++ C++;宏中的串联

C++ C++;宏中的串联,c++,c-preprocessor,stringification,C++,C Preprocessor,Stringification,我定义了以下一组宏(我从第一个答案中得到),试图使用宏“LOCATION\u PREFIX”来“捕获”代码行的位置(将传递给将执行日志记录的其他函数) 输出: “t.cpp”(8):这里 “t.cpp”(9):在这里 我希望输出为: t、 cpp(8):这里 t、 cpp(9):这边 非常感谢您的帮助 您不需要第一次调用STRINGIZE2,因为文件名已经是带引号的字符串: #define STRINGIZE(f,l) f "(" STRINGIZE2(l) "):" #define STRIN

我定义了以下一组宏(我从第一个答案中得到),试图使用宏“LOCATION\u PREFIX”来“捕获”代码行的位置(将传递给将执行日志记录的其他函数)

输出:

“t.cpp”(8):这里
“t.cpp”(9):在这里

我希望输出为:

t、 cpp(8):这里
t、 cpp(9):这边


非常感谢您的帮助

您不需要第一次调用
STRINGIZE2
,因为文件名已经是带引号的字符串:

#define STRINGIZE(f,l) f "(" STRINGIZE2(l) "):"
#define STRINGIZE2(x) #x
#define LOCATION_PREFIX STRINGIZE(__FILE__, __LINE__)

int main(){
  printf("%s here\n", LOCATION_PREFIX);
  printf("%s over here\n", LOCATION_PREFIX);

  return 1;
}

您不需要第一次调用
STRINGIZE2
,因为文件名已经是带引号的字符串:

#define STRINGIZE(f,l) f "(" STRINGIZE2(l) "):"
#define STRINGIZE2(x) #x
#define LOCATION_PREFIX STRINGIZE(__FILE__, __LINE__)

int main(){
  printf("%s here\n", LOCATION_PREFIX);
  printf("%s over here\n", LOCATION_PREFIX);

  return 1;
}

干杯工作完美,非常感谢您的快速响应。。。我将尽快接受答案。请注意,您也可以删除
STRINGIZE
f
参数,并直接将
\uuuu文件\uuuu
放入其中。我没有这样做,所以这与你的代码有着明确的关系。我做了更改以删除文件传递,STRINGIZE现在只接受(l)。干杯!工作完美,非常感谢您的快速响应。。。我将尽快接受答案。请注意,您也可以删除
STRINGIZE
f
参数,并直接将
\uuuu文件\uuuu
放入其中。我没有这样做,所以这与您的代码有明确的关系,但是。进行了更改以删除文件传递,STRINGIZE现在只接受(l)。