c++ base64 decode utf-8
- User
c++ base64 decode utf-8
Assistant
Here is how to base64 decode a string that is UTF-8 encoded in C++:
#include <iostream> #include <string> #include <boost/archive/iterators/base64_from_binary.hpp> #include <boost/archive/iterators/transform_width.hpp> std::string base64_decode(const std::string& encoded_string) { using namespace boost::archive::iterators; typedef transform_width<base64_from_binary<std::string::const_iterator>, 8, 6> Base64Decode; std::string decoded(Base64Decode(encoded_string.begin()), Base64Decode(encoded_string.end())); return decoded; } int main() { std::string encoded = "SGVsbG8gd29ybGQh"; std::string decoded = base64_decode(encoded); std::cout << decoded << "\n"; }The key points are:
- Use the boost::archive::iterators base64 decoding iterator to decode the base64 string
- The input string is treated as UTF-8 encoded
- The output is a std::string holding the decoded UTF-8 bytes
This decodes the base64 string and returns the UTF-8 decoded result.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.