Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A class similar to CString

Status
Not open for further replies.

Realazad

Programmer
Apr 5, 2002
15
US
Hi all,

in my current work so far I have been using CStrings extensively, but now I am told that my data is not restricted to strings and can be any kind of "byte". Does anyone know of a class or has example that works similar to CString (in terms of functions etc) but works on "byte"s instead.

Thanks a lot
Azad
 
I suggest as follows:

CString s('\0',2);
s.SetAt(1,100);
cout<<(int)s[1];
 
Thanx for the reply minhhoa.

My problem relates more to the fact that CString will not work correctly with binary data (it will terminate at the first available NULL). Because of that, I am unable to use it with data obtained from binary files (like PDFs, DOCs etc). I like CStrings because of their ease of use, and that's why I was wondering if an equivalent is written/read by someone for unsigned characters.

Thanks once again
Azad
 
How about string in STL.
string is just basic_string<char>, and you could create a new one :
basic_string<unsigned char>.
I use that a lot for handling binary data.
The only thing is you have to take care when assigning values : If your data contains binary zero, some constructors / operators terminate when the zero is seen - but you can use the assign() function with a length parameter - and then a binary zero will be included in your data.
It works quite well.
Besides it is portable ...
/JOlesen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top