命名空间
变体
操作

std::source_location::file_name

来自 cppreference.cn
 
 
 
 
constexpr const char* file_name() const noexcept;
(since C++20)

返回由此对象表示的当前源文件的名称,表示为 null 结尾的字节字符串。

目录

[编辑] 参数

(无)

[编辑] 返回值

由此对象表示的当前源文件的名称,表示为 null 结尾的字节字符串。

[编辑] 示例

#include <iostream>
#include <source_location>
 
void print_this_file_name(
    std::source_location location = std::source_location::current())
{
    // Name of file that contains the call site of this function.
    std::cout << "File: " << location.file_name() << '\n';
}
 
int main()
{
#line 1 "cppreference.cpp"
    print_this_file_name();
}

输出

File: cppreference.cpp

[编辑] 参见

返回由此对象表示的行号
(公共成员函数) [编辑]
返回由此对象表示的列号
(公共成员函数) [编辑]
返回由此对象表示的函数名称(如果有)
(公共成员函数) [编辑]
获取词法上包含表达式或语句的源文件的名称,该表达式或语句的求值由 stacktrace_entry 表示
(std::stacktrace_entry 的公共成员函数) [编辑]
文件名和行信息