
- C++ Library - Home
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- The C++ STL Library
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- The C++ Advanced Library
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ Library -
- C++ STL Library Cheat Sheet
- C++ STL - Cheat Sheet
- C++ Programming Resources
- C++ Programming Tutorial
- C++ Useful Resources
- C++ Discussion
C++ Library -
The
Before the introduction of
Including Header
To include the
#include
Functions of Header
Below is list of all functions from
Sr.No | Functions & Description |
---|---|
1 |
current
It constructs a new source_location corresponding to the location of the call site. |
2 |
line
It return the line number represented by this object. |
3 |
column
It return the column number represented by this object. |
4 |
file_name
It return the file name represented by this object. |
5 |
funtion_name
It return the name of the function represented by this object. |
Getting Function Name
In the following example, we are going to invoke the source_location::current() and retrieve the function name.
#include#include void x(const std::source_location & loc = std::source_location::current()) { std::cout << "Result : " << loc.function_name() << '\n'; } void y() { x(); } int main() { y(); }
Output
Output of the above code is as follows −
Result : void y()
Combining Multiple Source Location
Consider the following example, where we are going to combine the column number, line number into one log message.
#include#include void a(const std::string & message, const std::source_location & location = std::source_location::current()) { std::cout << "Message: " << message << "\n"; std::cout << "Line: " << location.line() << "\n"; std::cout << "Column: " << location.column() << "\n"; } int main() { a("WELCOME"); return 0; }
Output
Following is the output of the above code −
Message: WELCOME Line: 10 Column: 6