最終更新日時(UTC):
が更新

履歴 編集

function
<string>

std::operator+

template <class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
  operator+(const basic_string<charT, traits, Allocator>& lhs,
            const basic_string<charT, traits, Allocator>& rhs); // (1)

template <class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
  operator+(basic_string<charT, traits, Allocator>&& lhs,
            const basic_string<charT, traits, Allocator>& rhs); // (2) C++11 から

template <class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
  operator+(const basic_string<charT, traits, Allocator>& lhs,
            basic_string<charT, traits, Allocator>&& rhs);      // (3) C++11 から

template <class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
  operator+(basic_string<charT, traits, Allocator>&& lhs,
            basic_string<charT, traits, Allocator>&& rhs);      // (4) C++11 から

template <class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
  operator+(const charT* lhs,
            const basic_string<charT, traits, Allocator>& rhs); // (5)

template <class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
  operator+(const charT* lhs,
            basic_string<charT, traits, Allocator>&& rhs);      // (6) C++11 から

template <class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
  operator+(charT lhs,
            const basic_string<charT, traits, Allocator>& rhs); // (7)

template <class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
  operator+(charT lhs,
            basic_string<charT, traits, Allocator>&& rhs);      // (8) C++11 から

template <class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
  operator+(const basic_string<charT, traits, Allocator>& rhs,
            const charT* lhs);                                  // (9)

template <class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
  operator+(basic_string<charT, traits, Allocator>&& rhs,
            const charT* lhs);                                  // (10) C++11 から

template <class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
  operator+(const basic_string<charT, traits, Allocator>& rhs,
            charT lhs);                                         // (11)

template <class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
  operator+(basic_string<charT, traits, Allocator>&& rhs,
            charT lhs);                                         // (12) C++11 から

概要

basic_string オブジェクトの連結を行う。

戻り値

備考

(5)、(6) の形式の lhs、および、(9)、(10) の形式の rhs の文字列長算出のために traits::length() が使用される

#include <iostream>
#include <string>

int main()
{
  std::string s1("Hell");
  std::string s2("world");

  std::string s3 = s1 + 'o' + ", " + s2 + '!';

  std::cout << s3 << '\n';
}

出力

Hello, world!

参照

append 文字/文字列を追加する
push_back 文字を追加する
insert 文字/文字列を挿入する