Best data type to store the values like 21.6.7.1 in C/C++
In 21.6.7.1, 21 represents the some segment, 6 represents some lane inside that segment and so on and so forth. The individual values need to be extracted.
One way to represent this is string, any other way which is better a开发者_Python百科nd more convenient than string?
A structure with a four fields? An array of 4 elements, can also be an option.
A bit field would let you store the value within a 32-bit integer.
Use std::pair<pair<int,int>,pair<int,int>>
or tuple<int,int,int,int>
, if you don't want to have structure. Remember with both pair
and tuple
, there is no runtime penalty on accessing the elements.
I would use an array of four values: easy to compare, easy to read and to manage in future revisions of the code.
精彩评论