std::basic_string<CharT,Traits,Allocator>:: pop_back
| Classes | ||||
|
(C++17)
|
||||
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
void
pop_back
(
)
;
|
(constexpr C++20以降) | |
文字列の最後の文字を削除します。
erase ( end ( ) - 1 ) に相当します。
|
empty() が true の場合、動作は未定義です。 |
(C++26まで) |
|
empty() が true の場合:
|
(C++26以降) |
目次 |
計算量
定数。
例外
例外を送出しません。
注記
libstdc++では、
pop_back()
はC++98モードでは
利用できません
。
例
#include <cassert> #include <iomanip> #include <iostream> #include <string> int main() { std::string str("Short string!"); std::cout << "Before: " << std::quoted(str) << '\n'; assert(str.size() == 13); str.pop_back(); std::cout << "After: " << std::quoted(str) << '\n'; assert(str.size() == 12); str.clear(); // str.pop_back(); // undefined behavior }
出力:
Before: "Short string!" After: "Short string"
不具合報告
以下の動作変更欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。
| DR | 適用対象 | 公開時の動作 | 正しい動作 |
|---|---|---|---|
| LWG 534 | C++98 |
std::basic_string
にはメンバー関数
pop_back()
が存在しなかった
|
追加された |
関連項目
|
末尾に文字を追加する
(公開メンバ関数) |
|
|
文字を削除する
(公開メンバ関数) |