Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

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

      From cppreference.com
      <cpp‎ |string‎ |basic string
       
       
       
      std::basic_string
       
      void push_back( CharT ch);
      (constexpr since C++20)

      Appends the given characterch to the end of the string.

      Contents

      [edit]Parameters

      ch - the character to append

      [edit]Return value

      (none)

      [edit]Complexity

      Amortized constant.

      [edit]Exceptions

      If the operation would causesize() to exceedmax_size(), throwsstd::length_error.

      If an exception is thrown for any reason, this function has no effect (strong exception safety guarantee).

      [edit]Example

      Run this code
      #include <iomanip>#include <iostream>#include <string> int main(){std::string str{"Short string"};std::cout<<"1) "<<std::quoted(str)<<", size: "<< str.size()<<'\n';     str.push_back('!');std::cout<<"2) "<<std::quoted(str)<<", size: "<< str.size()<<'\n';}

      Output:

      1) "Short string", size: 122) "Short string!", size: 13

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 7C++981) the description was missing in the C++ standard
      2) the parameter type wasconst CharT
      1) description added
      2) changed toCharT
      LWG 847C++98there was no exception safety guaranteeadded strong exception safety guarantee

      [edit]See also

      removes the last character
      (public member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/string/basic_string/push_back&oldid=177142"

      [8]ページ先頭

      ©2009-2025 Movatter.jp