⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qtextstream.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
*/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    codec (the default codec is QTextCodec::codecForLocale()) before    it is written to the stream.    \sa setFieldWidth(), setCodec()*/QTextStream &QTextStream::operator<<(const QString &string){    Q_D(QTextStream);    CHECK_VALID_STREAM(*this);    d->putString(string);    return *this;}/*!    \overload    Writes \a array to the stream. The contents of \a array are    converted with QString::fromAscii().*/QTextStream &QTextStream::operator<<(const QByteArray &array){    Q_D(QTextStream);    CHECK_VALID_STREAM(*this);    d->putString(QString::fromAscii(array.constData(), array.length()));    return *this;}/*!    \overload    Writes the constant string pointed to by \a string to the stream. \a    string is assumed to be in ISO-8859-1 encoding. This operator    is convenient when working with constant string data. Example:    \code        QTextStream out(stdout);        out << "Qt rocks!" << endl;    \endcode    Warning: QTextStream assumes that \a string points to a string of    text, terminated by a '\0' character. If there is no terminating    '\0' character, your application may crash.*/QTextStream &QTextStream::operator<<(const char *string){    Q_D(QTextStream);    CHECK_VALID_STREAM(*this);    d->putString(QLatin1String(string));    return *this;}/*!    \overload    Writes \a ptr to the stream as a hexadecimal number with a base.*/QTextStream &QTextStream::operator<<(const void *ptr){    Q_D(QTextStream);    CHECK_VALID_STREAM(*this);    int oldBase = d->integerBase;    NumberFlags oldFlags = d->numberFlags;    d->integerBase = 16;    d->numberFlags |= ShowBase;    d->putNumber(reinterpret_cast<qint64>(ptr), false);    d->integerBase = oldBase;    d->numberFlags = oldFlags;    return *this;}/*!    \relates QTextStream    Calls QTextStream::setIntegerBase(2) on \a stream and returns \a    stream.    \sa oct(), dec(), hex(), {QTextStream manipulators}*/QTextStream &bin(QTextStream &stream){    stream.setIntegerBase(2);    return stream;}/*!    \relates QTextStream    Calls QTextStream::setIntegerBase(8) on \a stream and returns \a    stream.    \sa bin(), dec(), hex(), {QTextStream manipulators}*/QTextStream &oct(QTextStream &stream){    stream.setIntegerBase(8);    return stream;}/*!    \relates QTextStream    Calls QTextStream::setIntegerBase(10) on \a stream and returns \a    stream.    \sa bin(), oct(), hex(), {QTextStream manipulators}*/QTextStream &dec(QTextStream &stream){    stream.setIntegerBase(10);    return stream;}/*!    \relates QTextStream    Calls QTextStream::setIntegerBase(16) on \a stream and returns \a    stream.    \sa bin(), oct(), dec(), {QTextStream manipulators}*/QTextStream &hex(QTextStream &stream){    stream.setIntegerBase(16);    return stream;}/*!    \relates QTextStream    Calls QTextStream::setNumberFlags(QTextStream::numberFlags() |    QTextStream::ShowBase) on \a stream and returns \a stream.    \sa noshowbase(), forcesign(), forcepoint(), {QTextStream manipulators}*/QTextStream &showbase(QTextStream &stream){    stream.setNumberFlags(stream.numberFlags() | QTextStream::ShowBase);    return stream;}/*!    \relates QTextStream    Calls QTextStream::setNumberFlags(QTextStream::numberFlags() |    QTextStream::ForceSign) on \a stream and returns \a stream.    \sa noforcesign(), forcepoint(), showbase(), {QTextStream manipulators}*/QTextStream &forcesign(QTextStream &stream){    stream.setNumberFlags(stream.numberFlags() | QTextStream::ForceSign);    return stream;}/*!    \relates QTextStream    Calls QTextStream::setNumberFlags(QTextStream::numberFlags() |    QTextStream::ForcePoint) on \a stream and returns \a stream.    \sa noforcepoint(), forcesign(), showbase(), {QTextStream manipulators}*/QTextStream &forcepoint(QTextStream &stream){    stream.setNumberFlags(stream.numberFlags() | QTextStream::ForcePoint);    return stream;}/*!    \relates QTextStream    Calls QTextStream::setNumberFlags(QTextStream::numberFlags() &    ~QTextStream::ShowBase) on \a stream and returns \a stream.    \sa showbase(), noforcesign(), noforcepoint(), {QTextStream manipulators}*/QTextStream &noshowbase(QTextStream &stream){    stream.setNumberFlags(stream.numberFlags() &= ~QTextStream::ShowBase);    return stream;}/*!    \relates QTextStream    Calls QTextStream::setNumberFlags(QTextStream::numberFlags() &    ~QTextStream::ForceSign) on \a stream and returns \a stream.    \

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -