c++ - Visual C++ 和超长字符串

标签 c++ string visual-c++ boost string-literals

我正在尝试将第三方库移植到 Visual C++ 2013。该库有一些非常长的字符串,这些字符串似乎是 Base64 编码的数据。我将它们拆分为多个字符串文字,每个字符串文字都低于 Visual C++ 对字符串文字施加的 2,600 多个字符限制,但即便如此,仍有一些在连接后超过了 65,535 个字符的限制。

使用归结为:

boost::any value = +"abcd...";

有人可以建议一种使用超过 65k 的文字数据初始化 boost::any 的方法吗?

编辑:执行此操作的代码是从 XML 文件自动生成的。有数万个这样的值。对于 65,535 的限制,只有两个太长。

这使得任何使用动态内存分配(例如 std::string)的解决方案都没有吸引力,因为它会被代码生成实用程序应用于所有数以万计的解决方案,当只有两个需要它;动态内存分配会很昂贵。我更喜欢编译时解决方案。

最佳答案

引用自 nonius 修订日志

commit ec0e32ea96e8c0b1c7068f80207c586e6c4ba7aa
Author: Martinho Fernandes <email-in-commit>
Date:   Wed Feb 19 02:44:43 2014 +0100

    Shutting up MSVC warning.
    
    Dear Microsoft C/C++ Optimizing Compiler,
    
    I hate you. After I chopped up my HTML template into tiny, tiny string pieces to appease you tiny fixed-size buffers,
    I thought we could maybe be friends after all. But no. You had to go and give me more bullshit. You had to start your
    ridiculous warning bullshit. The warning bullshit that there is no way to turn off without leaking crap to user code.
    
    You're a joke.
    
    Sincerely,
    
    rmf

commit 8f10050a3217d94af1d3fb12e1e3752ab33c8159
Author: Martinho Fernandes <email-in-commit>
Date:   Tue Feb 18 19:35:26 2014 +0100

    Now with no string pieces larger than 11k
    
    Dear Microsoft C/C++ Optimizing Compiler,
    
    It was a bit hilarious when you complained about that ~200kiB string
    literal. The standard even has only a recommendation of 64kiB. This
    16380 bytes per string piece bullshit, though? This is just ridiculous.
    
    I hope this is the last hoop I have to jump through.
    
    Sincerely,
    
    rmf

commit 6b6a098e4e43c7f8d5e5fd580f6e6be463132f81
Author: Martinho Fernandes <email-in-commit>
Date:   Tue Feb 18 19:02:05 2014 +0100

    HTML template string broken into pieces that are assembled on first use.
    
    Dear Microsoft C/C++ Optimizing Compiler,
    
    The 1990s called. They want their 64kiB fixed-size buffers back.
    I didn't pay for 32GiB of RAM so that you could whine about a string
    literal that is a few hundred kiB big.
    
    Fuck You.
    
    Sincerely,
    
    rmf

我可以向您保证,这里已经报告了问题

您会注意到习惯性的 WONTFIX 响应。当然,这只是形式。显然在最新版本中发生了一些变化:

Is @R.MartinhoFernandes around? James told me that they've fixed the limitations on string literal lengths in VC2015 :)jalf on Apr 25 10:33 PM

根据上下文,我们可以得出这可能是 James McNellis .

之前有过关于此限制细节的讨论 on march 5th .


关于c++ - Visual C++ 和超长字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30341683/

相关文章:

c++ - 在 C++ 中使用模板的 2s 幂数组

c++ - 如果复制列表初始化允许显式构造函数会出现什么问题?

Java 字符串或对象的哈希集比较

windows - cl.exe 标志或设置以在/O1 或更高级别禁用尾调用优化(相当于 gcc -fno-optimize-sibling-calls)

c++ - 确定内存位置是否更改值

c++ - 关于使用每个函数结构(参数对象)模拟 "named arguments"以获取函数调用选项的问题?

c++ - 2个相互连接的对象内部的共享指针

python 正则表达式以逗号或空格分隔(但保留字符串原样)

python - 我正在使用电话号码模块来验证电话号码。它运行良好,但我只需要国家号码作为输出

c++ - 我可以使用 MS 工具将浮点错误转变为 C++ 异常吗?