String operations, printing to stdout
I'm not very fit with the QString class. I need to build a string representation of data which is a mixture of text and data. Is there a more elegant way than doing this?
Code:
QList<float> angles;
string = "data starts here: ";
for (int i = 0; i <angles->size(); i++)
{
temp.sprintf("\t%.2f", angles.at(i));
string.append(temp);
}
And then what's the best way to print this string to stdout? All I know is printf from C and I can't get that to work with Qstring.
Thanks
Cruz
Re: String operations, printing to stdout
Try something like this:
Code:
#include <QtDebug>
//...
QString string
("data starts here: ");
for(int i=0;i<angles->size();++i)
string
+=QString::number(angles.
at(i
),
'f',
2);
qDebug() << string;
Re: String operations, printing to stdout
Code:
#include <iostream>
...
std::cout << sometext.toLocal8Bit().constData() << 1 << " " << 1.3;
...
or I don't understand? :)
Re: String operations, printing to stdout
Even
Code:
qDebug() << angles;
works.