std::source_location::column
From cppreference.com
< cpp | utility | source location
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Utilities library
Type support (basic types, RTTI)
Library feature-test macros (C++20)
(C++11)
(C++20)
(C++26)
(C++20)
Coroutine support (C++20)
Contract support (C++26)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)(C++20)
(C++20)(C++20)(C++20)
General utilities
Relational operators (deprecated in C++20)
(C++20)(C++20)(C++20)
(C++20)(C++20)(C++20)
(C++20)
Swap and type operations
Common vocabulary types
std::source_location
Member functions
Creation
Field access
source_location::column
constexpr std::uint_least32_t column() const noexcept;
(since C++20)
Returns an implementation-defined value representing some offset from the start of the line represented by this object (i.e., the column number). Column numbers are presumed to be 1-indexed.
Contents
[edit] Parameters
(none)
[edit] Return value
An implementation-defined value representing some offset from the start of the line represented by this object (i.e., the column number).
An implementation is encouraged to use 0
when the column number is unknown.
[edit] Example
Run this code
#include <iostream> #include <source_location> template<typename T = std::source_location > inline void pos(const T& location = T::current()) { std::cout << "(" << location.line() << ':' << location.column() << ") "; } int main() { // ↓: column #9 pos(); std::cout << "Proxima\n"; // row #18 pos(); std::cout << "Centauri\n"; // row #19 // ↑: column #11 }
Possible output:
(18:9) Proxima (19:11) Centauri