string::copy

size_t copy (char* s, size_t len, size_t pos = 0) const;
功能:把string的pos位置开始的len字节copy到s
注意:s的最后要手动添加字符串结束标志

#include <iostream>
#include <string>

using namespace std;

int main()
{
char buf[20];
string str("i love lyy");
size_t len = str.copy(buf, 4, 2);
buf[len] = '';
cout << buf << endl;
return 0;
}

原文地址:https://www.cnblogs.com/xpylovely/p/12085179.html