|
-
October 10th, 2003, 12:53 PM
#1
handling binary streams?
I am building a web server. And some of the data that will be tramsitted back to the browser are images. From what I understand, images have embedded zeros in them.
Can I use the string class to handle it? Or do I need some kind of byte stream? Or a simple char array?
-
October 10th, 2003, 01:17 PM
#2
You can use a string (actually only a char array), but you can't treat it as a string. You will have to store the length, and you can't use string functions like strcpy instead use memcpy.
-
October 10th, 2003, 02:36 PM
#3
You can use std::string to hold binary data, including embedded nulls. The member functions to use to store data in a std::string is std::string::assign().
To return a pointer to the binary data, the member function to use is std::string: ata().
Regards,
Paul McKenzie
-
October 10th, 2003, 03:35 PM
#4
Would you recommend using std::string for this purpose? I am
having a little trouble getting my head around streams and
memory buffers
Wakeup in the morning and kick the day in the teeth!! Or something like that.
"i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."
-
October 10th, 2003, 03:57 PM
#5
Originally posted by souldog
Would you recommend using std::string for this purpose? I am
having a little trouble getting my head around streams and
memory buffers
I've stored binary data in std::string's (images and binary file data), and have had no problems.
Regards,
Paul McKenzie
-
October 10th, 2003, 06:42 PM
#6
Originally posted by Paul McKenzie
You can use std::string to hold binary data, including embedded nulls. The member functions to use to store data in a std::string is std::string::assign().
To return a pointer to the binary data, the member function to use is std::string:  ata().
Regards,
Paul McKenzie
Great, I was hoping I could use std::string. Thank you
-
October 12th, 2003, 06:08 AM
#7
You can also use std::vector<char> or std::vector<unsigned char>. It's got most of the same methods as std::string but does not try to append a nul to the end.
-rick
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|