std::source...n::file_name(3)
π NAME π
std::source_location::file_name - std::source_location::file_name
okay so bestie, welcome to the std::source...n::file_name(3) page from the C++ Standard Libary manual β yes, the manual name literally says Libary, and Iβm not fixing it, thatβs canon ππ
. This whole page is about std::source_location::file_name, and the NAME line is iconic in its redundancy: std::source_location::file_name - std::source_location::file_name. periodt.
π Synopsis π
constexpr const char* file_name() const noexcept; (since C++20)
so this function is constexpr, returns const char*, takes no args, is const, and is noexcept, and itβs been here (since C++20), no cap. It returns the name of the current source file represented by this object, represented as a null-terminated byte string. thatβs the vibe. β¨
π«Ά Parameters π«Ά
(none) β literally no parameters, bestie. not even one. π«Ά
πΈ Return value πΈ
The name of the current source file represented by this object, represented as a null-terminated byte string. thatβs the whole return value, and it ate. π
π¦ Example π¦
hereβs the example, run it if you want:
// Run this code
#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();
}
π Output π
the output is giving:
File: cppreference.cpp
π See also π
the see-also squad is right here, bestie:
lineβ return the line number represented by this object (public member function).columnβ return the column number represented by this object (public member function).function_nameβ return the name of the function represented by this object, if any (public member function).source_file(C++23)β gets the name of the source file that lexically contains the expression or statement whose evaluation is represented by thestacktrace_entry(public member function ofstd::stacktrace_entry).Filename and line informationβ also in the see-also list, and weβre including it because every detail stays, periodt. π«Ά
xoxo π β sourced from http://cppreference.com, version/date 2024.06.10, and filed under std::source...n::file_name(3). bye bestie, go get that file name! ππ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms