How do I include extremely long literals in C++ source?

后端 未结 5 1792
陌清茗
陌清茗 2020-12-21 01:12

I\'ve got a bit of a problem. Essentially, I need to store a large list of whitelisted entries inside my program, and I\'d like to include such a list directly -- I don\'t w

5条回答
  •  一整个雨季
    2020-12-21 01:52

    Let's assume you actually need to store a string >64k characters (i.e. all of the above "just don't do that" solutions don't apply.)

    To make MSVC happy, instead of saying:

    const char *foo = "abcd...";
    

    You can convert your >64k character string to individual characters represented as integers:

    const char foo[] = { 97, 98, 99, 100, ..., 0 };
    

    Where each letter has been converted to its ascii equivalent (97 == 'a', etc.), and a NUL terminator has been added at the end.

    MSVC2010 at least is happy with this.

提交回复
热议问题