码迷,mamicode.com
首页 > 其他好文 > 详细

string::copy

时间:2019-12-23 18:49:52      阅读:55      评论:0      收藏:0      [点我收藏+]

标签:char   字符串   功能   字符   pos   size_t   turn   include   clu   

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] = ‘\0‘;
cout << buf << endl;
return 0;
}

string::copy

标签:char   字符串   功能   字符   pos   size_t   turn   include   clu   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!