开发者

How much "data" you can put into a string?

As programmers, we work with strings a lot. Most of the time, I use them开发者_开发技巧 without thinking about them too much. Lately though, I have been using strings to return copious amounts of information from a function with no problem. My latest example is a binary tree with 10's of 1000's of entries. I have a recursive function that simply keeps adding to the string with a newline character at the end. This function gave no trouble.

So is there any kind of "limit" on how many characters you can put in a string or are you only limited by the amount of memory available?


The real limit on the size a string object can reach is returned by member max_size.

from here.

Link specific to max_size

So yeah, it's implementation-specific.


No, the only limit is available contiguous memory. There are no artificial limits imposed on string length; the length of a string is kept in a size_t variable, the maximum value of which is the largest addressable byte in the system (be it 8 or 16 or 32 or 64 bit or whatever).


It's very big but not unlimited though. You can use string::max_size to return the maximum number of characters that the string object can hold. Note that the returned value may vary from system to system.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜