public member function
<string>
std::string::copysize_t copy (char* s, size_t len, size_t pos = 0) const;
Copy sequence of characters from string
Copies a substring of the current value of the string object into the array pointed by s. This substring contains the len characters that start at position pos.The function does not append a null character at the end of the copied content.
size_t is an unsigned integral type (the same as member type string::size_type).
1
2
3
4
5
6
7
8
9
10
11
12
13
// string::copy
#include <iostream>
#include <string>
int main ()
{
char buffer[20];
std::string str ("Test string...");
std::size_t length = str.copy(buffer,6,5);
buffer[length]='\0';
std::cout << "buffer contains: " << buffer << '\n';
return 0;
}
Output:
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.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4