If you know the size of the array, and are not going to be manipulating it directly, then what you have:
Code:
unsigned char dns[512] = {1,1, 1,0, 0,1, 0,0, 0,0, 0,0};
Is fine, no need to go after STL just to be a hit up every language feature. If you need to concatenate a bunch of stuff into some sort of container, you could do some funny stuff with a vector I guess:
Code:
unsigned char dns[512] = {1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0}; // does it need to be 512?
unsigned char moredata[512] = { 0 }; // more data you need to build into something?
std::vector<unsigned char> v;
v.resize(sizeof dns);
std::copy(dns, dns + sizeof dns, v.begin());
v.resize(v.size() + sizeof moredata);
std::copy(moredata, moredata + sizeof moredata, v.begin() + sizeof dns);
Or something.
Code:
std::string dns = "111001000000";
dns.c_str(); // Returns a (const?) char* to the string in the object
You want something like this, I suppose? If you're in a situation where you have to use a union and struct to send and receive this header without conversion errors, then you may be better off using an array. I'm not sure a string object directly reflects the size of the string it holds. I wouldn't quote me on that, though. It can be tricky introducing C++ into network libraries that are written for C.
That string will contain ascii values, and stuff. His data is not null-terminated and not really meant to be represented by a string.