CppDS.com

C++ 98 11 14 17 20 手册

std::source_location::column

来自cppreference.com
 
 
工具库
通用工具
日期和时间
函数对象
格式化库 (C++20)
(C++11)
关系运算符 (C++20 中弃用)
整数比较函数
(C++20)
swap 与类型运算
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
常用词汇类型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等字符串转换
(C++17)
(C++17)
 
 
constexpr std::uint_least32_t column() const noexcept;
(C++20 起)

返回表示从此对象所表示的行起始的偏移的实现定义值(即列号)。列号预设为从 1 开始。

参数

(无)

返回值

表示从此对象所表示的行起始的偏移的实现定义值(即列号)。

鼓励实现在列号未知时使用 0

示例

#include <iostream>
#include <string_view>
#include <source_location>
 
template<typename T = std::source_location>
inline void pos(const T& location = T::current())
{
    std::cout
        << "("
        << location.line()
        << ':' 
        << location.column()
        << ") ";
}
 
auto main() -> int
{
    pos(); std::cout << "Proxima\n";
    pos(); std::cout << "Centauri\n";
}

可能的输出:

(18:5) Proxima
(19:5) Centauri

参阅

返回此对象所表示的行号
(公开成员函数)
返回此对象所表示的文件名
(公开成员函数)
返回此对象表示的函数名,若它存在
(公开成员函数)
关闭