Why sizeof(string) = 4?

P

peter koch

gary said:
Hi,
Who can say something about the class of string? Why sizeof(string) = 4?

Thanks.

sizeof(std::string) might be four on some implementations, 8, 16 or 24
on others. It all depends on the actual implementation of std::string
of which the standard does not say anything.

/Peter
 
F

Ferdi Smit

gary said:
Hi,
Who can say something about the class of string? Why sizeof(string) = 4?

Thanks.

Probably because your specific implementation of that class uses a
single pointer to the memory of the string. Which in this case is 4
bytes (32 bits). All this depends on implementation tho.

If you want to know the number of characters in your string, you ought
to use the size() member.

--
Regards,

Ferdi Smit (M.Sc.)
Email: (e-mail address removed)
Room: C0.07 Phone: 4229
INS3 Visualization and 3D Interfaces
CWI Amsterdam, The Netherlands
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top