By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 825 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

unsigned char * to string

P: n/a
Possibly a dumb question, but my c++ experience isn't that great.

I have a method:

static XMLRequest *parseXMLRequest(unsigned char *byte_buffer, size_t
length)
{}

byte_buffer is a pointer to a unsigned char array, but inside the
method I need to use it as a string to pass to another method. Can
anyone tell me the easiest/best way to convert? I've tried a couple of
things I thought might work, but I've had no luck so far.

Thanks

Jun 19 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
da**********@gmail.com wrote:
Possibly a dumb question, but my c++ experience isn't that great.

I have a method:

static XMLRequest *parseXMLRequest(unsigned char *byte_buffer, size_t
length)
{}

byte_buffer is a pointer to a unsigned char array, but inside the
method I need to use it as a string to pass to another method. Can
anyone tell me the easiest/best way to convert? I've tried a couple of
things I thought might work, but I've had no luck so far.


Just cast it to (char*). What problems are you encountering?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 19 '06 #2

P: n/a
Dan
I was getting "could not be converted errors" I hadn't even thought of
casting. It seems to work now, thanks!

But can you tell me what happens when I cast? Is it making a copy of
the variable?
Victor Bazarov wrote:
da**********@gmail.com wrote:
Possibly a dumb question, but my c++ experience isn't that great.

I have a method:

static XMLRequest *parseXMLRequest(unsigned char *byte_buffer, size_t
length)
{}

byte_buffer is a pointer to a unsigned char array, but inside the
method I need to use it as a string to pass to another method. Can
anyone tell me the easiest/best way to convert? I've tried a couple of
things I thought might work, but I've had no luck so far.


Just cast it to (char*). What problems are you encountering?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


Jun 19 '06 #3

P: n/a
posted:
Possibly a dumb question, but my c++ experience isn't that great.

I have a method:

static XMLRequest *parseXMLRequest(unsigned char *byte_buffer, size_t
length)
{}

byte_buffer is a pointer to a unsigned char array, but inside the
method I need to use it as a string to pass to another method. Can
anyone tell me the easiest/best way to convert?

#include <cstddef>

class SomeClass {
public:

class XMLRequest {};
static XMLRequest *parseXMLRequest(unsigned char*,std::size_t)
{
static XMLRequest req;

return &req;
}
};
int main()
{
char buffer[60];

SomeClass().parseXMLRequest(reinterpret_cast<unsig ned char*>(&*buffer),
sizeof buffer );
}


--

Frederick Gotham
Jun 19 '06 #4

P: n/a
Dan wrote:
Victor Bazarov wrote:
da**********@gmail.com wrote:
Possibly a dumb question, but my c++ experience isn't that great.

I have a method:

static XMLRequest *parseXMLRequest(unsigned char *byte_buffer, size_t
length)
{}

byte_buffer is a pointer to a unsigned char array, but inside the
method I need to use it as a string to pass to another method. Can
anyone tell me the easiest/best way to convert? I've tried a couple of
things I thought might work, but I've had no luck so far.

Just cast it to (char*). What problems are you encountering?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


I was getting "could not be converted errors" I hadn't even thought of
casting. It seems to work now, thanks!

But can you tell me what happens when I cast? Is it making a copy of
the variable?


1. Please do not top-post. Rearranged to conform with comp.lang.c++
netiquette.

2. The cast doesn't make a copy, it tells the compiler "Please use this
unsigned char * as a char * instead, and yes, I know what I'm doing."
Whether or not you know what you're doing is up to you and your code.
Jun 19 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.