std::basic_string_view<CharT,Traits>::front

出自cppreference.com
 
 
 
 
constexpr const_reference front() const;
(C++17 起)

返回到視圖首字符的引用。

如果 empty()true,那麼行為未定義。

(C++26 前)

如果 empty()true,那麼:

  • 如果實現是硬化實現,那麼就會發生契約違背
  • 如果實現不是硬化實現,那麼行為未定義。
(C++26 起)

返回值

data_[0]

複雜度

常數。

示例

#include <iostream>
#include <string_view>

int main()
{
    for (std::string_view str{"ABCDEF"}; !str.empty(); str.remove_prefix(1))
        std::cout << str.front() << ' ' << str << '\n';
}

輸出:

A ABCDEF
B BCDEF
C CDEF
D DEF
E EF
F F

參閱

訪問最末字符
(公開成員函數) [編輯]
檢查視圖是否為空
(公開成員函數) [編輯]
(DR*)
訪問首字符
(std::basic_string<CharT,Traits,Allocator> 的公開成員函數) [編輯]