命名空间
变体
操作

std::experimental::source_location::line

来自 cppreference.cn
constexpr std::uint_least32_t line() const noexcept;
(库基础 TS v2)

返回此对象表示的行号。

目录

[编辑] 参数

(无)

[编辑] 返回值

此对象表示的行号。

[编辑] 示例

#include <experimental/source_location>
#include <iostream>
#include <string_view>
using std::experimental::source_location;
 
inline void cur_line(
    const std::string_view message = "",
    const source_location& location = source_location::current())
{
    std::cout
        << location.line() // <- the call-site line #
        << ") "
        << message; 
}
 
int main()
{
    cur_line("++" "\n");
    cur_line(); std::cout << "Hello," "\n";
    cur_line(); std::cout << "C++20!" "\n";
    cur_line("--" "\n");
}

输出

18) ++
19) Hello,
20) C++20!
21) --

[编辑] 参阅

返回此对象表示的列号
(public 成员函数) [编辑]
返回此对象表示的文件名
(public 成员函数) [编辑]
返回此对象表示的函数名(如果有)
(public 成员函数) [编辑]
C++ 文档,关于 文件名与行信息