Getting information about a string

The max_size method will give the maximum size of the string of the specified character type on your computer architecture and this can be surprisingly large. For example, on a 64-bit Windows computer with 2 GB of memory, max_size for a string object will return 4 billion characters, and for a wstring object the method will return 2 billion characters. This is clearly more than the memory in the machine! The other size methods return more meaningful values. The length method returns the same value as the size method, that is, how many items (characters) there are in the string. The capacity method indicates how much memory is already allocated for the string in terms of the number of characters.

You can ...

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.