c++ - 带有字符串的奇怪 Qt 代码

标签 c++ qt qstring

我找到了我 friend 的 Qt 代码,他在两个 QString 上使用模运算符,如下所示:

QString result = oneString % twoString;

这是什么意思?

最佳答案

这只是连接 QString 的另一种(更有效的)方式,如 the manual 中所述。

QStringBuilder uses expression templates and reimplements the '%' operator so that when you use '%' for string concatenation instead of '+', multiple substring concatenations will be postponed until the final result is about to be assigned to a QString. At this point, the amount of memory required for the final result is known. The memory allocator is then called once to get the required space, and the substrings are copied into it one by one.

关于c++ - 带有字符串的奇怪 Qt 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12027977/

相关文章:

c++ - 如何在跳水比赛中降低循环内的最高/最低分数?

c++ - QT : multimedia 中的未知模块

linux - 在嵌入式 Linux 上处理设备插入和移除

c++ - 像 C 的 printf 一样向 QTextEdit 显示格式化文本

c++ - 观察 QStringList 的新项目

c++ - 如何在 QString 的 asctime 中删除换行符

c++ - 为什么我的静态库这么大?

c++ - 当您多次声明同一个对象/变量时会发生什么(新手)

c++ - C中的MPI和多维数组分配

c++ - 销毁QHBoxLayout