令人惊讶的是,Qt5已弃用先前版本中存在的StringBuilder类.我的另一个选择是使用QTextStream,这是不方便的,因为我必须传入它写入的缓冲区(例如QFile,QString).
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('!');
你可以使用你需要的所有东西,比如std :: stringstream.