June 2025
Intermediate to advanced
1093 pages
33h 24m
English
Sometimes it is interesting for analysis purposes to know in which file and line the execution is currently taking place. For this, there are the __FILE__, __LINE__, and __func__ macros.
With C++20, this is now part of the standard library. With the <source_location> header, you can get the necessary information via source_location::current():
#include <source_location>#include <iostream>int main() { const auto loc = std::source_location::current(); std::cout << "In " << loc.file_name() << " in line " << loc.line() << " in function " << loc.function_name() << "\n";}
This currently outputs the following for me:
In 11pModularisierung.md in line 687 in function int main()
Normally, you will see a .cpp ...
Read now
Unlock full access