std::source_location::line
来自 cppreference.cn
< cpp | utility | source location
constexpr std::uint_least32_t line() const noexcept; |
(自 C++20 起) | |
返回此对象表示的行号。
目录 |
[edit] 参数
(无)
[edit] 返回值
此对象表示的行号。
鼓励实现方式在行号未知时返回 0
。
[edit] 示例
运行此代码
#include <iostream> #include <string_view> #include <source_location> inline void cur_line( const std::string_view message = "", const std::source_location& location = std::source_location::current()) { std::cout << location.line() // <- the line # of a call site << ") " << message; } int main() { cur_line("++\n"); cur_line(); std::cout << "Hello,\n"; cur_line(); std::cout << "C++20!\n"; cur_line("--\n"); }
输出
17) ++ 18) Hello, 19) C++20! 20) --
[edit] 参见
返回此对象表示的列号 (公有成员函数) | |
返回此对象表示的文件名 (公有成员函数) | |
返回此对象表示的函数名(如果有) (公有成员函数) | |
获取词法上关联于 stacktrace_entry 表示的求值的行号( std::stacktrace_entry 的公有成员函数) | |
文件名和行信息 |