Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert std::string to std::vector<uint8_t>?

Tags:

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

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> ?

like image 770
Rahul Iyer Avatar asked Jan 19 '17 08:01

Rahul Iyer


People also ask

What is the difference between std :: string and std :: vector?

std::string offers a very different and much expanded interface compared to std::vector<> . While the latter is just a boring old sequence of elements, the former is actually designed to represent a string and therefore offers an assortment of string-related convenience functions.

How do you convert STD string to Lpwstr?

std::wstring stemp = std::wstring(s. begin(), s. end()); LPCWSTR sw = stemp. c_str();

How do you convert a string vector to an int vector?

Using stoi() function Starting with C++11, you can use the stoi function to convert a string to an int, defined in the <string> header file. It throws std::invalid_argument if the string cannot be parsed. However, it can extract the integer value 1 from the strings like 1s .


1 Answers

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

std::string str; std::vector<uint8_t> vec(str.begin(), str.end()); 
like image 144
DeiDei Avatar answered Sep 22 '22 00:09

DeiDei