命名空间
变体
操作

std::source_location::column

来自 cppreference.cn
 
 
 
 
constexpr std::uint_least32_t column() const noexcept;
(C++20 起)

返回一个由实现定义的值,表示此对象所表示行开头的某个偏移量(即列号)。列号假定为 1-indexed。

目录

[编辑] 参数

(无)

[编辑] 返回值

一个由实现定义的值,表示此对象所表示行开头的某个偏移量(即列号)。

当列号未知时,建议实现使用 0

[编辑] 示例

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

可能的输出

(18:9) Proxima
(19:11) Centauri

[编辑] 参阅

返回此对象表示的行号
(公共成员函数) [编辑]
返回此对象表示的文件名
(公共成员函数) [编辑]
返回此对象表示的函数名(如果有)
(公共成员函数) [编辑]
文件名和行信息