c++ - 大量文本应该如何存储?

标签 c++ text

<分区>

应该如何存储大量硬编码的文本?在 txt 文件中?在代码本身(在字符串中)?还是另一种方式?例如帮助对话的文本

最佳答案

只要“大量”意味着小于兆字节,我会说只需将其存储在 std::string 中即可。如果没有更多详细信息,您将无法获得更好的答案。

鉴于您的评论:

by large amopunts i mean between a paragraph and a page, by hard coded i mean something set by the programmer that will never change

听起来你想存储少量的散文。您肯定希望将其存储在 const std::string 中:

const std::string ipsum =
    "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut nec massa mauris.\n"
    "Maecenas luctus venenatis mauris, ut pulvinar nisl ultricies sed. Mauris\n"
    "adipiscing aliquet massa id dapibus. Praesent leo nisl, sollicitudin quis\n"
    "sodales in, mattis ac tortor. Phasellus semper vehicula nibh sit amet pulvinar.\n"
    "Nam faucibus, turpis non feugiat consequat, massa lacus euismod lorem, in\n"
    "viverra orci justo a odio.";

关于c++ - 大量文本应该如何存储?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18324300/

相关文章:

c++ - 开关量不是整数

html - 如何沿着 div 底部正确对齐不同大小的文本?

c++ - 获取 C# 输出字符串参数值到 C++ BSTR*?

c++ - 加权有向图中从节点返回自身的最短距离

c++ - 存储可本地化字符串的惯用 Qt 方式?

html - 如何使用 CSS 使链接居中

java - JAVA从目录中逐行读取多个文本文件

linux - 如何在 linux 中返回文件中第一次出现文本的行号

python - 在文档中索引单词的最有效方法?

C++11 与 C++98 转换运算符行为发生变化?