Other Modifying Methods: copy()
and swap()
The copy()
method copies a string
object, or part thereof, to a designated character array:
size_type copy(charT* s, size_type n, size_type pos = 0) const;
In this case, s
points to the destination array, n
indicates the number of characters to copy, and pos
indicates the position in the string
object from which copying begins. Copying proceeds for n
characters or until the last character in the string
object, whichever comes first. The function returns the number of characters copied. The method does not append a null character, and it is up to the programmer to see that the array is large enough to hold the copy.
Caution
The copy()
method does not append a null character, nor does it check whether ...
Get C++ Primer Plus now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.