The trick to turning numerical constants into strings is the STR and XSTR macros, defined below:
#include <iostream>
//! See https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html
#define XSTR(a) STR(a)
#define STR(a) #a
#define LINE_AS_STR XSTR(__LINE__)
#define FILE_AND_LINE __FILE__ ":" LINE_AS_STR
int main() {
constexpr const char* line = LINE_AS_STR;
std::cout << "That was line \"" << line << "\"" << std::endl;
std::cout << FILE_AND_LINE << std::endl;
}
output:
That was line "11"
example.cpp:13
https://godbolt.org/z/xzE1nWeMd