fork(4) download
  1. #include <iomanip>
  2. #include <iostream>
  3. #include <sstream>
  4. #include <string>
  5. #include <vector>
  6.  
  7. std::string hex_representation(const std::vector<int>& v) {
  8. std::stringstream stream;
  9. for (const auto num : v) {
  10. stream << "0x" << std::hex << std::setw(2) << std::setfill('0') << num
  11. << ' ';
  12. }
  13. return stream.str();
  14. }
  15.  
  16. int main(int argc, char* argv[]) {
  17. std::vector<int> v = {1, 2, 3, 10, 11, 12};
  18. const auto hex_str = hex_representation(v);
  19. std::cout << hex_str << '\n';
  20. return 0;
  21. }
  22.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
0x01 0x02 0x03 0x0a 0x0b 0x0c