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

Questions about the string class.

P: n/a
Using gcc 3.3 on MAC OS X.

i have a variable called:
string x;

I need to copy the string using memcpy so how do I get the pointer to
the data and its length in bytes?
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
DrBob wrote:
Using gcc 3.3 on MAC OS X.

i have a variable called:
string x;

I need to copy the string using memcpy so how do I get the pointer to
the data and its length in bytes?


Getting the string: x.c_str();

Getting the length in bytes: (x.length() + 1) * sizeof(string::value_type)
Remove the +1 bit if you don't need the terminating NULL-character.

--
Unforgiven

"You can't rightfully be a scientist if you mind people thinking
you're a fool."
Jul 22 '05 #2

P: n/a
"DrBob" <bo*******@yahoo.com> wrote...
Using gcc 3.3 on MAC OS X.

i have a variable called:
string x;

I need to copy the string using memcpy so how do I get the pointer to
the data and its length in bytes?


Is this a homework assignment?

Take a C++ book and look at the member functions of the
'basic_string' template.

Jul 22 '05 #3

P: n/a
DrBob escribió:
i have a variable called:
string x;

I need to copy the string using memcpy so how do I get the pointer to
the data and its length in bytes?


Use the string member function copy.

Regards.
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.