我正在将 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/