Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt sscanf equivalent

Tags:

c++

qt

Say I have this:

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

Is there a Qt alternative to sscanf so I can read the numbers into the int variables?

like image 893
sashoalm Avatar asked Oct 22 '12 13:10

sashoalm


2 Answers

QTextStream provides the equivalent of the standard library's streams. Don't forget that the text stream should be destroyed before the string.

QString mystring = "67 49 213 59";
QTextStream myteststream(&mystring);
int a = 0, b = 0, c = 0, d = 0;
myteststream >> a >> b >> c >> d;
like image 52
slaphappy Avatar answered Nov 15 '22 01:11

slaphappy


int a, b, c, d;
QString s("67 49 213 59");
QTextStream(&s) >> a >> b >> c >> d;
like image 36
CapelliC Avatar answered Nov 15 '22 00:11

CapelliC