std::source_location::column

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.

# Declarations

constexpr std::uint_least32_t column() const noexcept;

(since C++20)

# Return value

An implementation-defined value representing some offset from the start of the line represented by this object (i.e., the column number).

# Example

#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
}

# See also