std::basic_string<CharT,Traits,Allocator>::front
提供: cppreference.com
<tbody>
</tbody>
<tbody class="t-dcl-rev ">
</tbody><tbody>
</tbody>
<tbody class="t-dcl-rev ">
</tbody><tbody>
</tbody>
CharT& front(); |
(C++11以上) (C++20未満) |
|
constexpr CharT& front(); |
(C++20以上) | |
const CharT& front() const; |
(C++11以上) (C++20未満) |
|
constexpr const CharT& front() const; |
(C++20以上) | |
文字列の最初の文字を指す参照を返します。 empty() == true の場合、動作は未定義です。
引数
(なし)
戻り値
最初の文字を指す参照。 operator[](0) と同等。
計算量
一定。
例
Run this code
#include <iostream>
#include <string>
int main()
{
{
std::string s("Exemplary");
char& f = s.front();
f = 'e';
std::cout << s << '\n'; // "exemplary"
}
{
std::string const c("Exemplary");
char const& f = c.front();
std::cout << &f << '\n'; // "Exemplary"
}
}
出力:
exemplary
Exemplary
関連項目
(C++11) |
最後の文字にアクセスします (パブリックメンバ関数) |