Max length of a string literal?

丶灬走出姿态 提交于 2019-12-09 17:51:50

问题


I am trying to create a long string literal, which I store inside a std::string. If I create a literal up to approximately 2600 characters, everything prints fine. If I go beyond that number of symbols, I only get some random garbage characters printed.

I have been using the C standard as guidance, environmental limits are specified as "4095 characters in a string literal (after concatenation)". But the code is written in C++.

So my question is, what is the minimum amount of characters in a C++ string literal?

(The problem might possibly be elsewhere in the code, but I would like to ensure that I don't pass a limit set by the standard. The text is printed in a RichEdit control, so I doubt that one is the culprit.)


回答1:


The minimum is specified in

Annex B
Implementation quantities [implimits]

Characters in a string literal (after concatenation) [65 536].

But note that:

1) Because computers are finite, C++ implementations are inevitably limited in the size of the programs they can successfully process. Every implementation shall document those limitations where known. This documentation may cite fixed limits where they exist, say how to compute variable limits as a function of available resources, or say that fixed limits do not exist or are unknown.

2) The limits may constrain quantities that include those described below or others. The bracketed number following each quantity is recommended as the minimum for that quantity. However, these quantities are only guidelines and do not determine compliance. (emphasis mine)

Your implementation should provide you with this number though.



来源:https://stackoverflow.com/questions/13125419/max-length-of-a-string-literal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!