gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 16:28:49 24 4
gpt4 key购买 nike

我找到了我 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com