gpt4 book ai didi

c++ - Qt5 是否有类似于 StringBuilder 或 StringBuffer 的类?

转载 作者:太空狗 更新时间:2023-10-29 20:37:18 25 4
gpt4 key购买 nike

令人惊讶的是,Qt5 弃用了以前版本中存在的 StringBuilder 类。我的另一个选择是使用 QTextStream,这并不方便,因为我必须传入它写入的缓冲区(例如 QFileQString) .

C++ (std::stringstream)、C# (StringBuilder) 和 Java (StringBuffer) 都有这些类。 Qt 怎么样?

最佳答案

QStringBuilder 未弃用。来自 Qt docs :

In 4.6, an internal template class QStringBuilder has been added along with a few helper functions. This class is marked internal and does not appear in the documentation, because you aren't meant to instantiate it in your code. Its use will be automatic, as described below. The class is found in src/corelib/tools/qstringbuilder.cpp if you want to have a look at it.

他们的代码示例:

#include <QStringBuilder>

QString hello("hello");
QStringRef el(&hello, 2, 3);
QLatin1String world("world");
QString message = hello % el % world % QChar('!');

你可以使用你需要的 C++ 中的任何东西,比如 std::stringstream

关于c++ - Qt5 是否有类似于 StringBuilder 或 StringBuffer 的类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35235762/

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