Namespaces
Variants

std::basic_string<CharT,Traits,Allocator>:: pop_back

From cppreference.net
std::basic_string
void pop_back ( ) ;
(constexpr C++20부터)

문자열에서 마지막 문자를 제거합니다.

다음에 해당합니다: erase ( end ( ) - 1 ) .

만약 empty() true 이면, 동작은 정의되지 않습니다.

(C++26까지)

만약 empty() true 이면:

  • 구현이 hardened 된 경우, contract violation 이 발생합니다. 또한 계약 위반 핸들러가 "observe" 평가 의미론 하에 반환하면, 동작은 정의되지 않습니다.
  • 구현이 hardened되지 않은 경우, 동작은 정의되지 않습니다.
(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() 이 없었음 추가됨

참고 항목

끝에 문자를 추가함
(public member function)
문자를 제거함
(public member function)