Help with setFieldWidth in QTextStream
-
Hey guys,
I am writing a simple piece to output a data array with fixed width into a txt file on PC. My code is listed below:
@
QFile file("sf-book.txt");
file.open(QIODevice::WriteOnly | QIODevice::Text );QTextStream out(&file);
out.setIntegerBase(10);
out.setRealNumberNotation(QTextStream::FixedNotation);
out.setRealNumberPrecision(4);
out.setFieldAlignment(QTextStream::AlignRight);
out.setFieldWidth(14);
out.setPadChar('.');for (int row = 0; row < 3; row++) {
out << (float)row << 1.234 << endl;
}
@The content in the output text is like:
........0.0000........1.2340.............
........1.0000........1.2340.............
........2.0000........1.2340.............So my question is that why there are extra dots after the two data on each row? setFieldWidth also works for format characters?
I tried enable and disable QIODevice::Text, but the result is the same.Thanks in advance.
-
Hi,
In your code, every "element" that you put to the out stream has field width = 14. This also applies to the endl.
As you can see you have 13 extra dots, the 14th sign is the newline. -
Thanks for the info! :)