I have a CLinux device, that i need to transform some data. The input is something like
char mytest[] = "020441010C0000003131203131203131313103";
and i need to have
mytest2[] = {0x02,0x04,0x41,0x01,0x0C,0x00,0x00,0x00,0x31,0x31,0x20,0x31,0x31,0x20,0x31,0x31,0x31,0x31,0x03}
This is the code that i've tried, but it doesn't compile cause the sstream is not on the device OS.. Can some give me another solution to transform the data?
#include <iostream>
#include <sstream>
int main() {
std::string myStr = "1122AA010A";
std::stringstream ss;
int n;
for(int i = 0; i<myStr.length(); ) {
std::istringstream(myStr.substr(i,2))>>std::hex>>n;
ss<<(char)n;
i += 2;
}
std::string result = ss.str();
std::cout<<"\n"<<result<<"\n";
return 0;
}