加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 如何将char的向量转换为stringstream

发布时间:2020-12-16 10:35:27 所属栏目:百科 来源:网络整理
导读:是否可以将char矢量转换为std :: stringstream?例如: std::vectorunsigned char data;std::stringstream st(????); 有什么方法可以将数据值赋给st吗? 解决方法 如果我们看一下 std::stringstream 构造函数,我们会看到第二个构造函数是: explicit basic_s
是否可以将char矢量转换为std :: stringstream?例如:

std::vector<unsigned char> data;
std::stringstream st(????);

有什么方法可以将数据值赋给st吗?

解决方法

如果我们看一下 std::stringstream构造函数,我们会看到第二个构造函数是:

explicit basic_stringstream( const std::basic_string<CharT,Traits,Allocator>& str,ios_base::openmode mode = ios_base::in|ios_base::out );

basic_string的构造者包括:

template< class InputIt >
basic_string( InputIt first,InputIt last,const Allocator& alloc = Allocator() );

因此,我们可以做到:

std::vector<unsigned char> data(20);

std::stringstream st(std::string(data.begin(),data.end()));

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读