String length limit in MSVC during compile?

╄→尐↘猪︶ㄣ 提交于 2019-12-12 05:27:07

问题


I am converting C++ codes from Linux to windows (using Visual Studio 2013). But MSVC has length limit on string (around 2048 bytes?), the GCC doesn't instead. My problem is that, there is a config file containing several huge string, it works well under GCC. But MSVC reports compile error as

error C2026: string too big, trailing characters truncated.

The string is quite simple, CONFIGSTRING is huge.

const std::string CONFIGSTRING="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

Any solution for this problem? Can I separately compile the config file to object file using GCC under windows and link it to other files? If possible, anyone can briefly show me how to do it?


回答1:


According to the MSDN docs, this should work:

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

If this is still not sufficient, then do:

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?

No, they are using different C++ standard libraries.



来源:https://stackoverflow.com/questions/31460913/string-length-limit-in-msvc-during-compile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!