fork(4) download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <vector>
  4. #include <sstream>
  5.  
  6. typedef unsigned char BYTE;
  7.  
  8. int main() {
  9.  
  10. std::istringstream iss("1,3,8,b,e,ff,10");
  11. std::vector<BYTE> dataValues;
  12.  
  13. unsigned int num = 0;
  14. while(iss >> std::hex >> num || !iss.eof())
  15. {
  16. if(iss.fail())
  17. {
  18. iss.clear();
  19. char dummy;
  20. iss >> dummy;
  21. continue;
  22. }
  23. if(num <= 0xff) {
  24. dataValues.push_back(static_cast<BYTE>(num));
  25. }
  26. else {
  27. // Error single byte value expected
  28. }
  29. }
  30.  
  31. std::cout << std::hex << std::setfill('0');
  32. for(std::vector<BYTE>::const_iterator it = dataValues.begin();
  33. it != dataValues.end();
  34. ++it) {
  35. std::cout << "0x" << std::setw(2) << static_cast<unsigned int>(*it) << std::endl;
  36. }
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
0x01
0x03
0x08
0x0b
0x0e
0xff
0x10