"Bobrick" <pu******@gmail.comwrote in message
news:11**********************@51g2000cwl.googlegro ups.com...
Hi.
I'm in the process of making a GUI for a function someone else wrote,
and i've come across a type i'm unfamiliar with, namely
"std::vector<unsigned char>". I need to get the contents of this
variable into a form I can display in a text box, but i'm not sure what
to expect inside of the variable, whether I can just treat it like an
array e.t.c. Any help would be appreciated.
Thanks,
Bob
The vector itself you can pretty much treat as an array. The contents of
the unsigned chars will be values from 0 to 255. What those represent, I
don't know. Are they characters? Are they values? You'll have to look at
the way it's used to determine that.
The fact that it's unsigned char instead of plain char would lead me to
suspect it's used for it's values. Many ways to iterate through a vector.
The one that most C programs would understand would be:
// presume Array is std::vector<unsigned char>
for ( size_t i = 0; i < Array.size(); ++i )
std::cout << Array[i] << "\n";
Or you can iterate using iterators:
for ( std::vector<unsigned char>::iterator it = Array.begin(); it !=
Array.end(); ++it )
std::cout << *it << "\n";
In addition, an arrays memory is guaranteed to be contiguous.
unsigned char* vecp = &(Array[0]); // grab address of first unsigned char
for ( size_t i = 0; i < Array.size(); ++i )
std::cout << *(vecp + i) << "\n";