在Google Play游戏服务上保存游戏所需的数据格式为:std::vector<uint8_t>
,如“数据格式”中所述:https://developers.google.com/games/services/cpp/savedgames
我假设向量代表某种字节数组。那是对的吗 ?那么如何将std::string
转换为std::vector<uint8_t>
?
std::vector
有一个构造函数,仅用于此目的:
std::string str;
std::vector<uint8_t> vec(str.begin(), str.end());
添加到DeiDei的答案,如果已经构造了向量,则可以执行以下操作:
std::string str;
std::vector<uint8_t> vec;
vec.assign(str.begin(), str.end());