public static member function
static char_type* copy (char_type* dest, const char_type* src, size_t n);
Copy character sequence
Copies the sequence of n characters pointed by src to the array pointed by dest. Ranges shall not overlap.
All character traits types shall implement the function as if the individual characters were assigned using member assign.
- Pointer to an array where the copied characters are written.
- Pointer to an array with the n characters to copy.
- Number of characters to copy.
Notice that the function will consider that the length of both dest and src sequences is n characters, independently on whether any of them contains null-characters.
Member type char_type is the character type (i.e., the class template parameter in char_traits).
size_t is an unsigned integral type.
#include <iostream> // std::cout
#include <string> // std::char_traits
int main ()
char foo = "test string";
unsigned len = std::char_traits<char>::length(foo);
bar[len] = '\0'; // append null-character
std::cout << "foo contains: " << foo << '\n';
std::cout << "bar contains: " << bar << '\n';
foo contains: test string
bar contains: test string
Unless either dest or src does not point to an array long enough, this member function never throws exceptions (no-throw guarantee) in any of the standard specializations.
Otherwise, it causes undefined behavior.