有没有好的赋值方法呢?请教!

hzshuo 2002-08-21 01:28:18
有个vector<char> x 里面有很多字符,有个string y
有没有好的方法,让我把x里面的字符赋给string y呢?
...全文
65 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wetrust 2002-08-21
  • 打赏
  • 举报
回复
声明:
template <class InputIterator>
basic_string (InputIterator first, InputIterator last,
const Allocator& a = Allocator());
天外飞狐 2002-08-21
  • 打赏
  • 举报
回复
string y(x.begin(), x.end());
string 类有好几个构造函数,这是其中的一个。(其实string 不是一个类,只是一个typedef)
wliang 2002-08-21
  • 打赏
  • 举报
回复
#include <algorithm>

y.resize(x.size());
copy(x.begin(), x.end(), y.begin());//ok

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧