std::basic_string::copy
size_type copy( CharT* dest, size_type count, size_type pos = 0) const; | | |
---|
复制子字符串[pos, pos+count)
指向由dest
如果请求的子字符串持续到字符串的末尾,或者count == npos
,复制的子字符串是[pos, size())
得到的字符串不是以空结尾的.
如果pos > size()
,,,std::out_of_range
被扔了。
参数
dest | - | pointer to the destination character string |
---|---|---|
pos | - | position of the first character to include |
count | - | length of the substring |
返回值
复制的字符数。
例外
std::out_of_range
如果pos > size()
...
复杂性
线性在count
...
例
二次
#include <string>
#include <iostream>
int main()
{
std::string foo("quuuux");
char bar[7];
foo.copy(bar, sizeof bar);
bar[6] = '\0';
std::cout << bar << '\n';
}
二次
产出:
二次
quuuux
二次
另见
substr | returns a substring (public member function) |
---|
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com