• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    function
    <stacktrace>

    std::stacktrace_entry::source_file

    string source_file() const; // (1) C++23
    

    概要

    ソースファイル名を取得する。

    戻り値

    *thisで表される評価の式または文を字句的に含むソースファイルの推定または実際の名前、または空文字列を返す。

    例外

    内部のデータ構造、または結果文字列のためのメモリ確保ができない場合、std::bad_alloc例外を送出する。

    備考

    • この関数はメモリ確保以外のエラーを「利用可能な情報がない」ものとして扱い、その場合は例外を送出しない

    #include <iostream>
    #include <stacktrace>
    
    void g() {
      std::stacktrace st = std::stacktrace::current();
      std::stacktrace_entry entry = st[0];
    
      std::cout << entry.source_file() << std::endl;
    }
    
    void f() {
      g();
    }
    
    int main() {
      f();
    }
    

    出力例 (GCC)

    /app/example.cpp
    

    バージョン

    言語

    • C++23

    処理系