public member function
<string>
std::string::copy
size_t copy (char* s, size_t len, size_t pos = 0) const;
Copy sequence of characters from string
The function does not append a null character at the end of the copied content.
Parameters
- s
- Pointer to an array of characters.
The array shall contain enough storage for the copied characters. - len
- Number of characters to copy (if the string is shorter, as many characters as possible are copied).
- pos
- Position of the first character to be copied.
If this is greater than the string length, it throws out_of_range.
Note: The first character in the string is denoted by a value of 0 (not 1).
Return value
The number of characters copied to the array pointed by s. This may be equal to len or to length()-pos (if the string value is shorter than pos+len).size_t is an unsigned integral type (the same as member type string::size_type).
Example
|
|
Complexity
Linear in the number of characters copied.Iterator validity
No changes.Data races
The object is accessed.Exception safety
Strong guarantee: if an exception is thrown, there are no changes in the string.If s does not point to an array long enough, it causes undefined behavior.
If pos is greater than the string length, an out_of_range exception is thrown.
See also
- string::substr
- Generate substring (public member function)
- string::assign
- Assign content to string (public member function)
- string::c_str
- Get C string equivalent (public member function)
- string::replace
- Replace portion of string (public member function)
- string::insert
- Insert into string (public member function)
- string::append
- Append to string (public member function)