- string[meta header]
- std[meta namespace]
- function template[meta id-type]
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 オブジェクトの連結を行う。
-
(1)
basic_string<charT, traits, Allocator>(lhs).append(rhs) -
(4)
std::move(lhs.append(rhs))
(std::move(rhs.insert(0, lhs))とも等価) -
(5)
basic_string<charT, traits, Allocator>(lhs) + rhs -
(7)
basic_string<charT, traits, Allocator>(1, lhs) + rhs -
(9)
lhs +basic_string<charT, traits, Allocator>(rhs) -
(11)
lhs +basic_string<charT, traits, Allocator>(1, rhs)
(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';
}- +[color ff0000]
Hello, world!
| 名前 | 説明 |
|---|---|
append |
文字/文字列を追加する |
push_back |
文字を追加する |
insert |
文字/文字列を挿入する |