The Wayback Machine - https://web.archive.org/web/20160902013236/http://ja.cppreference.com:80/w/cpp/string/basic_string/replace
名前空間
変種
操作

std::basic_string::replace

提供: cppreference.com
< cpp‎ | string‎ | basic string

 
 
 
std::basic_string
メンバ関数
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_string::basic_string
basic_string::operator=
basic_string::assign
basic_string::get_allocator
要素アクセスの循環参照を解除するために使用されている
Original:
Element access
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_string::at
basic_string::operator[]
basic_string::front(C++11)
basic_string::back(C++11)
basic_string::data
basic_string::c_str
イテレータ
Original:
Iterators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_string::begin
basic_string::cbegin

(C++11)
basic_string::end
basic_string::cend

(C++11)
basic_string::rbegin
basic_string::crbegin

(C++11)
basic_string::rend
basic_string::crend

(C++11)
容量
Original:
Capacity
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_string::empty
basic_string::size
basic_string::length
basic_string::max_size
basic_string::reserve
basic_string::capacity
basic_string::shrink_to_fit(C++11)
操作
Original:
Operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_string::clear
basic_string::insert
basic_string::erase
basic_string::push_back
basic_string::pop_back(C++11)
basic_string::append
basic_string::operator+=
basic_string::compare
basic_string::replace
basic_string::substr
basic_string::copy
basic_string::resize
basic_string::swap
検索
Original:
Search
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_string::find
basic_string::rfind
basic_string::find_first_of
basic_string::find_first_not_of
basic_string::find_last_of
basic_string::find_last_not_of
定数
Original:
Constants
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_string::npos
非メンバ関数
Original:
Non-member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
operator+
operator==
operator!=
operator<
operator>
operator<=
operator>=
swap(std::basic_string)
operator<<
operator>>
getline
stoi
stol
stoll
(C++11)
(C++11)
(C++11)
stoul
stoull
(C++11)
(C++11)
stof
stod
stold
(C++11)
(C++11)
(C++11)
to_string(C++11)
to_wstring(C++11)
ヘルパークラス
Original:
Helper classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
hash<std::string>
hash<std::wstring>
hash<std::u32string>
hash<std::u16string>
(C++11)
 
basic_string& replace( size_type pos, size_type count,

                       const basic_string& str );

basic_string& replace( const_iterator first, const_iterator last,

                       const basic_string& str );
(1)
basic_string& replace( size_type pos, size_type count,

                       const basic_string& str,
                       size_type pos2, size_type count2 );

template<class InputIt >
basic_string& replace( const_iterator first, const_iterator last,

                       InputIt first2, InputIt last2 );
(2)
basic_string& replace( size_type pos, size_type count,

                       const CharT* cstr, size_type count2 );

basic_string& replace( const_iterator first, const_iterator last,

                       const CharT* cstr, size_type count2 );
(3)
basic_string& replace( size_type pos, size_type count,

                       const CharT* cstr );

basic_string& replace( const_iterator first, const_iterator last,

                       const CharT* cstr );
(4)
basic_string& replace( size_type pos, size_type count,

                       size_type count2, CharT ch );

basic_string& replace( const_iterator first, const_iterator last,

                       size_type count2, CharT ch );
(5)
basic_string& replace( const_iterator first, const_iterator last,
                       std::initializer_list<CharT> ilist );
(6) (C++11およびそれ以降)
新しい文字列を持つ[pos, pos + count)または[first, last)いずれかで示される文字列の一部を置き換え.
Original:
Replaces the part of the string indicated by either [pos, pos + count) or [first, last) with a new string.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
新しい文字列のいずれかを指定できます
Original:
The new string can be one of:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
1)
文字列str
Original:
string str
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
レンジ[pos2, pos2 + count2)strまたは部分文字列[first2, last2)
Original:
substring [pos2, pos2 + count2) of str or characters in the range [first2, last2)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
3)
文字列の最初のcount2のcharctersはcstrが指す
Original:
first count2 charcters of the character string pointed to by cstr
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
4)
NULLで終わる文字列はcstrが指す
Original:
null-terminated character string pointed to by cstr
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
5)
文字count2chコピー
Original:
count2 copies of character ch
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
6)
初期化子リストilistの文字
Original:
characters in the initializer list ilist
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目次

[編集]パラメータ

pos -
置換される文字列の開始
Original:
start of the substring that is going to be replaced
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
count -
置換される文字列の長さ
Original:
length of the substring that is going to be replaced
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
first, last -
置換される文字の範囲を指定します
Original:
range of characters that is going to be replaced
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
str -
交換のために使用する文字列
Original:
string to use for replacement
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
pos2 -
と交換する部分文字列の開始
Original:
start of the substring to replace with
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
count2 -
と置換する文字の数
Original:
number of characters to replace with
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
cstr -
交換のために使用する文字列へのポインタ
Original:
pointer to the character string to use for replacement
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ch -
交換のために使用する文字列値
Original:
character value to use for replacement
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
first2, last2 -
交換のために使用する文字の範囲を指定します
Original:
range of characters to use for replacement
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
init -
交換のために使用する文字を使用した初期化子リスト
Original:
initializer list with the characters to use for replacement
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
型の要件
-
InputItInputIterator

の要求を満足しなければなりません。

[編集]値を返します

*this

[編集]例外

std::out_of_range if pos > length() or pos2 > str.length()

std::length_error結果の文字列が可能な最大文字列の長さを(std::string::npos - 1)超えた場合
Original:
std::length_error if the resulting string will exceed maximum possible string length (std::string::npos - 1)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集]

#include <iostream>#include <string>   int main(){std::string str("The quick brown fox jumps over the lazy dog.");   str.replace(10, 5, "red");// (4)   str.replace(str.begin(), str.begin()+3, 1, 'A');// (5)   std::cout<< str <<'\n';}

出力:

A quick red fox jumps over the lazy dog.
close