Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::source_location::line

      From cppreference.com
      <cpp‎ |utility‎ |source location
       
       
      Utilities library
       
       
      constexprstd::uint_least32_t line()constnoexcept;
      (since C++20)

      Returns the line number represented by this object.

      Contents

      [edit]Parameters

      (none)

      [edit]Return value

      The line number represented by this object.

      An implementation is encouraged to return0 when the line number is unknown.

      [edit]Example

      Run this code
      #include <iostream>#include <string_view>#include <source_location> inlinevoid cur_line(conststd::string_view message="",conststd::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");}

      Output:

      17) ++18) Hello, 19) C++20! 20) --

      [edit]See also

      return the column number represented by this object
      (public member function)[edit]
      return the file name represented by this object
      (public member function)[edit]
      return the name of the function represented by this object, if any
      (public member function)[edit]
      gets the line number that lexically relates the evaluation represented by thestacktrace_entry
      (public member function ofstd::stacktrace_entry)[edit]
      Filename and line information
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/utility/source_location/line&oldid=150206"

      [8]ページ先頭

      ©2009-2026 Movatter.jp