Namespaces
Variants

std::source_location:: file_name

From cppreference.net
Utilities library
constexpr const char * file_name ( ) const noexcept ;
(自 C++20 起)

返回此对象所表示的当前源文件名称,以空终止字节字符串形式表示。

目录

参数

(无)

返回值

此对象表示的当前源文件名称,以空终止字节字符串形式表示。

示例

#include <iostream>
#include <source_location>
void print_this_file_name(
    std::source_location location = std::source_location::current())
{
    // 包含此函数调用点的文件名
    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 的公开成员函数)
文件名和行信息