gpt4 book ai didi

c++ - 编译期间 MSVC 中的字符串长度限制?

转载 作者:行者123 更新时间:2023-11-28 06:10:02 25 4
gpt4 key购买 nike

我正在将 C++ 代码从 Linux 转换到 Windows(使用 Visual Studio 2013)。但是 MSVC 对字符串有长度限制(大约 2048 字节?),而 GCC 没有。我的问题是,有一个包含几个巨大字符串的配置文件,它在 GCC 下运行良好。但是 MSVC 将编译错误报告为

error C2026: string too big, trailing characters truncated.

字符串很简单,CONFIGSTRING 很大。

const std::string CONFIGSTRING="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

这个问题有什么解决办法吗?我可以在Windows下使用GCC将配置文件单独编译为目标文件并将其链接到其他文件吗?如果可能的话,任何人都可以简要地告诉我如何去做?

最佳答案

根据 MSDN 文档,这应该有效:

const std::string str =
"xxxx" // Max 2048 bytes
"xxxx" // Max 2048 bytes
// ... and so on (up to 65535 bytes)
;

如果这还不够,那么做:

std::string str;
str = "part1";
str += "part2";
str += "part3"; // And so on.

Can I separately compile the config file to object file using GCC under windows and link it to other files?

不,他们使用不同的 C++ 标准库。

关于c++ - 编译期间 MSVC 中的字符串长度限制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31460913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com