std::basic_string<CharT,Traits,Allocator>::copy
| size_type copy( CharT* dest, size_type count, size_type pos = 0 ) const; |
(until C++20) | |
| constexpr size_type copy( CharT* dest, size_type count, size_type pos = 0 ) const; |
(since C++20) | |
Copies a substring [pos, pos+count) to character string pointed to by dest. If the requested substring lasts past the end of the string, or if count == npos, the copied substring is [pos, size()). The resulting character string is not null-terminated.
If pos > size(), std::out_of_range is thrown.
Contents |
[edit] Parameters
| dest | - | pointer to the destination character string |
| count | - | length of the substring |
| pos | - | position of the first character to include |
[edit] Return value
number of characters copied
[edit] Exceptions
std::out_of_range if pos > size().
[edit] Complexity
linear in count
[edit] Example
#include <string> #include <iostream> int main() { std::string foo("quuuux"); char bar[7]{}; foo.copy(bar, sizeof bar); std::cout << bar << '\n'; }
Output:
quuuux
[edit] See also
| returns a substring (public member function) | |
| copies characters (public member function of std::basic_string_view<CharT,Traits>)
| |
| (C++11) |
copies a range of elements to a new location (function template) |
| copies one buffer to another (function) |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
