字符串文字的最大长度? [英] Max length of a string literal?

查看:214
本文介绍了字符串文字的最大长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个长字符串文字,我存储在std :: string。如果我创建一个大约2600个字符的文字,一切打印得很好。如果我超过这个数字的符号,我只得到一些随机的垃圾字符打印。



我一直使用C标准作为指导,环境限制指定为4095字符串字符(连接后)。但是代码是用C ++编写的。



所以我的问题是,C ++字符串文字中的最小字符数是多少?



(问题可能在代码中的其他地方,但我想确保我没有通过标准设置的限制。文本是在RichEdit控件中打印的,所以我怀疑一个




b 附件B

实现数量[implimits]


字符串字符但是请注意:


1)因为计算机是有限的,C ++实现不可避免地限制了它们
可以成功处理的程序的大小。 本文档
可以引用存在的固定限制,说明如何计算作为可用
资源的函数的变量限制,或者说固定极限不存在或未知。


2)限制可以限制包括下面描述的或其他描述的数量。推荐每个数量后面的括号数
作为该数量的最小值。但是,这些数量仅为
,仅指导原则,不确定是否符合
。 (强调我)


您的实现应该为您提供此号码。


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.)

解决方案

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.

这篇关于字符串文字的最大长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆