if you want to store the numbers (for instance into an array of bytes) represented by the hexadecimal strings then try:
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdint>
#include <array>
#include <exception>
using namespace std;
uint8_t hex(const string & str)
{
uint8_t b = 0;
for (size_t n=0; n<2; ++n)
{
b <<= 4;
char c = str.at(n);
if ( c >= '0' && c <= '9')
b |= static_cast<uint8_t>(c-'0');
else if ( c >= 'A' && c <= 'F')
b |= static_cast<uint8_t>(c-'A'+0xA);
else if ( c >= 'a' && c <= 'f')
b |= static_cast<uint8_t>(c-'a'+0xA);
else
throw(invalid_argument("not an hex string"));
}
return b;
}
int main()
{
string line = "06 0D 00 B0 89 00 0D E7";
istringstream iss(line);
array<uint8_t, 8> data;
for (auto & d : data)
{
string s;
iss >> s;
d = hex(s);
}
for (const auto & d : data)
cout << static_cast<unsigned int>(d) << endl;
}
[update]
Following Jochen suggestion, there is no need for manula hex conversion:
#include <iostream>
#include <sstream>
#include <cstdint>
#include <array>
#include <exception>
using namespace std;
int main()
{
string line = "06 0D 00 B0 89 00 0D E7";
istringstream iss(line);
array<uint8_t, 8> data;
for (auto & d : data)
{
size_t pos = 0;
string s;
iss >> s;
d = static_cast<uint8_t>( stoul(s, &pos, 16));
if ( pos != 2)
throw(invalid_argument("not a byte hexadecimal representation"));
}
for (const auto & d : data)
cout << static_cast<unsigned int>(d) << endl;
}
[/update]