std::basic_string_view<CharT,Traits>::front
來自 cppreference.com
< cpp | string | basic string view
constexpr const_reference front() const; |
(C++17 起) | |
返回檢視中第一個字元的引用。如果 empty() == true,則行為未定義。
目錄 |
[編輯] 引數
(無)
[編輯] 返回值
對第一個字元的引用,等價於 operator[](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> 的公共成員函式) |