Questions about the string class.

D

DrBob

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?
 
U

Unforgiven

DrBob said:
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.
 
V

Victor Bazarov

DrBob said:
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.
 
?

=?iso-8859-1?Q?Juli=E1n?= Albo

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,148
Messages
2,570,838
Members
47,385
Latest member
Joneswilliam01

Latest Threads

Top