如何将std :: string转换为std :: vector< uint8_t&gt ;? [英] How to convert std::string to std::vector<uint8_t>?

查看:467
本文介绍了如何将std :: string转换为std :: vector< uint8_t&gt ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Google Play游戏服务上保存游戏所需的数据格式为: std :: vector< uint8_t> ,在
的数据格式下指定 https://developers.google.com/games/services/cpp/savedgames

The data format required to save games on google play game services is : std::vector<uint8_t> as specified under 'Data formats' on: https://developers.google.com/games/services/cpp/savedgames

我假设向量代表某种字节数组。那是对的吗 ?那么如何将 std :: string 转换为 std :: vector< uint8_t> 呢?

I am assuming the vector represents some kind of byte array. Is that correct ? So how does one convert an std::string to std::vector<uint8_t> ?

推荐答案

std :: vector 具有一个用于此目的的构造函数:

std::vector has a constructor just for this purpose:

std::string str;
std::vector<uint8_t> vec(str.begin(), str.end());

这篇关于如何将std :: string转换为std :: vector&lt; uint8_t&gt ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆