名稱空間
變體
操作

std::source_location::line

來自 cppreference.com
 
 
 
 
constexpr std::uint_least32_t line() const noexcept;
(C++20 起)

返回此物件表示的行號。

目錄

[編輯] 引數

(無)

[編輯] 返回值

此物件表示的行號。

當行號未知時,建議實現返回 0

[編輯] 示例

#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) --

[編輯] 參閱

返回此物件表示的列號
(公共成員函式) [編輯]
返回此物件表示的檔名
(公共成員函式) [編輯]
返回此物件表示的函式名(如果有)
(公共成員函式) [編輯]
獲取與 stacktrace_entry 表示的求值在詞法上相關的行號
(std::stacktrace_entry 的公共成員函式) [編輯]
檔名和行資訊