std::basic_string<CharT,Traits,Allocator>::copy
提供: cppreference.com
<tbody>
</tbody>
<tbody class="t-dcl-rev ">
</tbody><tbody>
</tbody>
size_type copy( CharT* dest, size_type count, size_type pos = 0 ) const; |
(C++20未満) | |
constexpr size_type copy( CharT* dest, size_type count, size_type pos = 0 ) const; |
(C++20以上) | |
部分文字列 [pos, pos+count) を dest の指す文字列にコピーします。 要求された部分文字列が文字列の終端を超える場合、または count == npos の場合、コピーされる部分文字列は [pos, size()) になります。 結果の文字列はヌル終端されません。
pos > size() の場合は std::out_of_range が投げられます。
引数
| dest | - | コピー先文字列を指すポインタ |
| count | - | 部分文字列の長さ |
| pos | - | 含める最初の文字の位置 |
戻り値
コピーした文字数。
例外
pos > size() の場合 std::out_of_range。
計算量
count に比例。
例
Run this code
#include <string>
#include <iostream>
int main()
{
std::string foo("quuuux");
char bar[7]{};
foo.copy(bar, sizeof bar);
std::cout << bar << '\n';
}
出力:
quuuux
関連項目
| 部分文字列を返します (パブリックメンバ関数) |