?? qtextstream.cpp
字號:
/*! \overload Reads a character from the stream and stores it in \a c. The character from the stream is converted to ISO-5589-1 before it is stored. \sa QChar::toLatin1()*/QTextStream &QTextStream::operator>>(char &c){ QChar ch; *this >> ch; c = ch.toLatin1(); return *this;}/*! Reads an integer from the stream and stores it in \a i, then returns a reference to the QTextStream. The number is casted to the correct type before it is stored. If no number was detected on the stream, \a i is set to 0. By default, QTextStream will attempt to detect the base of the number using the following rules: \table \header \o Prefix \o Base \row \o "0b" or "0B" \o 2 (binary) \row \o "0" followed by "0-7" \o 8 (octal) \row \o "0" otherwise \o 10 (decimal) \row \o "0x" or "0X" \o 16 (hexadecimal) \row \o "1" to "9" \o 10 (decimal) \endtable By calling setIntegerBase(), you can specify the integer base explicitly. This will disable the auto-detection, and speed up QTextStream slightly. Leading whitespace is skipped.*/QTextStream &QTextStream::operator>>(signed short &i){ IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(signed short);}/*! \overload Stores the integer in the unsigned short \a i.*/QTextStream &QTextStream::operator>>(unsigned short &i){ IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(unsigned short);}/*! \overload Stores the integer in the signed int \a i.*/QTextStream &QTextStream::operator>>(signed int &i){ IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(signed int);}/*! \overload Stores the integer in the unsigned int \a i.*/QTextStream &QTextStream::operator>>(unsigned int &i){ IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(unsigned int);}/*! \overload Stores the integer in the signed long \a i.*/QTextStream &QTextStream::operator>>(signed long &i){ IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(signed long);}/*! \overload Stores the integer in the unsigned long \a i.*/QTextStream &QTextStream::operator>>(unsigned long &i){ IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(unsigned long);}/*! \overload Stores the integer in the qlonglong \a i.*/QTextStream &QTextStream::operator>>(qlonglong &i){ IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(qlonglong);}/*! \overload Stores the integer in the qulonglong \a i.*/QTextStream &QTextStream::operator>>(qulonglong &i){ IMPLEMENT_STREAM_RIGHT_INT_OPERATOR(qulonglong);}/*! Reads a real number from the stream and stores it in \a f, then returns a reference to the QTextStream. The number is casted to the correct type. If no real number is detect on the stream, \a f is set to 0.0. Leading whitespace is skipped.*/QTextStream &QTextStream::operator>>(float &f){ IMPLEMENT_STREAM_RIGHT_REAL_OPERATOR(float);}/*! \overload Stores the real number in the double \a f.*/QTextStream &QTextStream::operator>>(double &f){ IMPLEMENT_STREAM_RIGHT_REAL_OPERATOR(double);}/*! Reads a word from the stream and stores it in \a str, then returns a reference to the stream. Words are separated by whitespace (i.e., all characters for which QChar::isSpace() returns true). Leading whitespace is skipped.*/QTextStream &QTextStream::operator>>(QString &str){ Q_D(QTextStream); CHECK_VALID_STREAM(*this); str.clear(); d->scan(0, 0, 0, QTextStreamPrivate::NotSpace); d->consumeLastToken(); const QChar *ptr; int length; if (!d->scan(&ptr, &length, 0, QTextStreamPrivate::Space)) { setStatus(ReadPastEnd); return *this; } str = QString(ptr, length); d->consumeLastToken(); return *this;}/*! \overload Converts the word to ISO-8859-1, then stores it in \a array. \sa QString::toLatin1()*/QTextStream &QTextStream::operator>>(QByteArray &array){ Q_D(QTextStream); CHECK_VALID_STREAM(*this); array.clear(); d->scan(0, 0, 0, QTextStreamPrivate::NotSpace); d->consumeLastToken(); const QChar *ptr; int length; if (!d->scan(&ptr, &length, 0, QTextStreamPrivate::Space)) { setStatus(ReadPastEnd); return *this; } for (int i = 0; i < length; ++i) array += ptr[i].toLatin1(); d->consumeLastToken(); return *this;}/*! \overload Stores the word in \a c, terminated by a '\0' character. If no word is available, only the '\0' character is stored. Warning: Although convenient, this operator is dangerous and must be used with care. QTextStream assumes that \a c points to a buffer with enough space to hold the word. If the buffer is too small, your application may crash. If possible, use the QByteArray operator instead.*/QTextStream &QTextStream::operator>>(char *c){ Q_D(QTextStream); *c = 0; CHECK_VALID_STREAM(*this); d->scan(0, 0, 0, QTextStreamPrivate::NotSpace); d->consumeLastToken(); const QChar *ptr; int length; if (!d->scan(&ptr, &length, 0, QTextStreamPrivate::Space)) { setStatus(ReadPastEnd); return *this; } for (int i = 0; i < length; ++i) *c++ = ptr[i].toLatin1(); *c = '\0'; d->consumeLastToken(); return *this;}/*! \internal */bool QTextStreamPrivate::putNumber(qulonglong number, bool negative){ QString tmp; if (negative) tmp = QLatin1Char('-'); else if (numberFlags & QTextStream::ForceSign) tmp = QLatin1Char('+'); if (numberFlags & QTextStream::ShowBase) { switch (integerBase) { case 2: tmp += QLatin1String("0b"); break; case 8: tmp += QLatin1String("0"); break; case 16: tmp += QLatin1String("0x"); break; default: break; } } tmp += QString::number(number, integerBase ? integerBase : 10); if (numberFlags & QTextStream::UppercaseBase) tmp = tmp.toUpper(); // ### in-place instead return putString(tmp);}/*! \internal \overload*/QTextStream &QTextStream::operator<<(QBool b){ return *this << bool(b);}/*! Writes the character \a c to the stream, then returns a reference to the QTextStream. \sa setFieldWidth()*/QTextStream &QTextStream::operator<<(QChar c){ Q_D(QTextStream); CHECK_VALID_STREAM(*this); d->putString(QString(c)); return *this;}/*! \overload Converts \a c from ASCII to a QChar, then writes it to the stream.*/QTextStream &QTextStream::operator<<(char c){ Q_D(QTextStream); CHECK_VALID_STREAM(*this); d->putString(QString(QChar::fromAscii(c))); return *this;}/*! Writes the integer number \a i to the stream, then returns a reference to the QTextStream. By default, the number is stored in decimal form, but you can also set the base by calling setIntegerBase(). \sa setFieldWidth(), setNumberFlags()*/QTextStream &QTextStream::operator<<(signed short i){ Q_D(QTextStream); CHECK_VALID_STREAM(*this); d->putNumber((qulonglong)qAbs(qlonglong(i)), i < 0); return *this;}/*! \overload Writes the unsigned short \a i to the stream.*/QTextStream &QTextStream::operator<<(unsigned short i){ Q_D(QTextStream); CHECK_VALID_STREAM(*this); d->putNumber((qulonglong)i, false); return *this;}/*! \overload Writes the signed int \a i to the stream.*/QTextStream &QTextStream::operator<<(signed int i){ Q_D(QTextStream); CHECK_VALID_STREAM(*this); d->putNumber((qulonglong)qAbs(qlonglong(i)), i < 0); return *this;}/*! \overload Writes the unsigned int \a i to the stream.*/QTextStream &QTextStream::operator<<(unsigned int i){ Q_D(QTextStream); CHECK_VALID_STREAM(*this); d->putNumber((qulonglong)i, false); return *this;}/*! \overload Writes the signed long \a i to the stream.*/QTextStream &QTextStream::operator<<(signed long i){ Q_D(QTextStream); CHECK_VALID_STREAM(*this); d->putNumber((qulonglong)qAbs(qlonglong(i)), i < 0); return *this;}/*! \overload Writes the unsigned long \a i to the stream.*/QTextStream &QTextStream::operator<<(unsigned long i){ Q_D(QTextStream); CHECK_VALID_STREAM(*this); d->putNumber((qulonglong)i, false); return *this;}/*! \overload Writes the qlonglong \a i to the stream.*/QTextStream &QTextStream::operator<<(qlonglong i){ Q_D(QTextStream); CHECK_VALID_STREAM(*this); d->putNumber((qulonglong)qAbs(i), i < 0); return *this;}/*! \overload Writes the qulonglong \a i to the stream.*/QTextStream &QTextStream::operator<<(qulonglong i){ Q_D(QTextStream); CHECK_VALID_STREAM(*this); d->putNumber(i, false); return *this;}/*! Writes the real number \a f to the stream, then returns a reference to the QTextStream. By default, QTextStream stores it using SmartNotation, with up to 6 digits of precision. You can change the textual representation QTextStream will use for real numbers by calling setRealNumberNotation(), setRealNumberPrecision() and setNumberFlags(). \sa setFieldWidth(), setRealNumberNotation(), setRealNumberPrecision(), setNumberFlags()*/QTextStream &QTextStream::operator<<(float f){ return *this << double(f);}/*! \overload Writes the double \a f to the stream.*/QTextStream &QTextStream::operator<<(double f){ Q_D(QTextStream); CHECK_VALID_STREAM(*this); char f_char; char format[16]; if (d->realNumberNotation == FixedNotation) f_char = 'f'; else if (d->realNumberNotation == ScientificNotation) f_char = (d->numberFlags & UppercaseBase) ? 'E' : 'e'; else f_char = (d->numberFlags & UppercaseBase) ? 'G' : 'g'; // generate format string register char *fs = format; // "%.<prec>l<f_char>" *fs++ = '%'; if (d->numberFlags & QTextStream::ForcePoint) *fs++ = '#'; *fs++ = '.'; int prec = d->realNumberPrecision; if (prec > 99) prec = 99; if (prec >= 10) { *fs++ = prec / 10 + '0'; *fs++ = prec % 10 + '0'; } else { *fs++ = prec + '0'; } *fs++ = 'l'; *fs++ = f_char; *fs = '\0'; QString num; num.sprintf(format, f); // convert to text if (f > 0.0 && (d->numberFlags & ForceSign)) num.prepend(QLatin1Char('+')); d->putString(num); return *this;}/*! Writes the string \a string to the stream, and returns a reference to the QTextStream. The string is first encoded using the assigned
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -