Is there any c++ class that can be used like a string. Which has all stuff needed like comparators and etc? I want to have something like string class that works on array of bytes instead of chars. I'm just asking because I don't want to write again something that already exists. I will use this class in std::map and etc.
That's exactly what an std::string
is. A char
is essentially a byte
. It takes up one byte of space and it accepts all logical and bitwise operators (bit shifting: <<
, >>
; logical comparisons: &
, |
; etc.).
If for some reason you need something like an std::string
but for a different datatype, simply use std::basic_string<DATATYPE>
. In the STL, string
itself is a typedef
for basic_string<char>
.
There is no such thing as byte
in c++
. You can use std::vector
with unsigned char
which has similar effect as byte in Java
for example.
typedef unsigned char BYTE;
typedef std::vector<BYTE> ByteString;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.