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>
?
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.
std::wstring stemp = std::wstring(s. begin(), s. end()); LPCWSTR sw = stemp. c_str();
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 .
std::vector
has a constructor just for this purpose:
std::string str; std::vector<uint8_t> vec(str.begin(), str.end());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With