标准没有指定字符串文字的最大限制,但建议最小尺寸.附件B – 实施数量
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.
Characters in a string literal (after concatenation) [65 536].
但是,标准中的相同部分也说明如下
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.
可以安全地假设5MB字符串文字将超过编译器强加的最大限制.您应该参考工具链的文档来确定对字符串文字施加的限制.
如果您使用的是Visual C编译器,则字符串文字的最大大小为16,384字节.从MSDN documentation
The maximum length of a string literal is 16,384 (16K) bytes. This limit applies to strings of type char[] and wchar_t[]. If a string literal consists of parts enclosed in double quotation marks, the preprocessor concatenates the parts into a single string, and for each line concatenated, it adds an extra byte to the total number of bytes.