Storing hexadecimal values from a std::string in a std::vector and vise versa?
问题 Let's say you've got a std::string("DEADBEEF") , what would be the most elegant way to store each two values in a std::vector (most likely a std::vector<unsigned char> , if possible) so the std::vector would look a little like { 0xDE, 0xAD, 0xBE, 0xEF } (if it was an array)? And what would be the nicest way to undo that ( std::vector<unsigned char> -> std::string ). 回答1: how about (no fancy stl juggling though): #include <string> #include <vector> // exception thrown by the encoder class