Qt sscanf equivalent

Qt sscanf equivalent

本文关键字:equivalent sscanf Qt      更新时间:2023-10-16

说我有这个:

QString mystring = "67 49 213 59";
int a, b, c, d;

是否有SSCANF的QT替代方案,以便我可以将数字读取到int变量中?

QTextStream提供了标准库流的等效。不要忘记,在字符串之前,应在之前销毁文本流。

QString mystring = "67 49 213 59";
QTextStream myteststream(&mystring);
int a = 0, b = 0, c = 0, d = 0;
myteststream >> a >> b >> c >> d;
int a, b, c, d;
QString s("67 49 213 59");
QTextStream(&s) >> a >> b >> c >> d;
QString str("67 49 213 59");
QStringList list = str.split(" ");
int a[list.count];
for (int i = 0; i < list.count; i++)
   a[i] = list[i].toInt();

您总是可以做

QByteArray oString = mystring.toAscii();
const char *pszString = oString.constData();

然后使用sscanf()正常。