The QTextStream class provides a convenient interface for reading and writing text. 更多...
| 頭: | #include <QTextStream> |
| qmake: | QT += core |
注意: 此類的所有函數 可重入 .
| enum | FieldAlignment { AlignLeft, AlignRight, AlignCenter, AlignAccountingStyle } |
| enum | NumberFlag { ShowBase, ForcePoint, ForceSign, UppercaseBase, UppercaseDigits } |
| flags | NumberFlags |
| enum | RealNumberNotation { ScientificNotation, FixedNotation, SmartNotation } |
| enum | Status { Ok, ReadPastEnd, ReadCorruptData, WriteFailed } |
| QTextStream () | |
| QTextStream (QIODevice * device ) | |
| QTextStream (FILE * fileHandle , QIODevice::OpenMode openMode = QIODevice::ReadWrite) | |
| QTextStream (QString * string , QIODevice::OpenMode openMode = QIODevice::ReadWrite) | |
| QTextStream (QByteArray * array , QIODevice::OpenMode openMode = QIODevice::ReadWrite) | |
| QTextStream (const QByteArray & array , QIODevice::OpenMode openMode = QIODevice::ReadOnly) | |
| virtual | ~QTextStream () |
| bool | atEnd () const |
| bool | autoDetectUnicode () const |
| QTextCodec * | codec () const |
| QIODevice * | device () const |
| QTextStream::FieldAlignment | fieldAlignment () const |
| int | fieldWidth () const |
| void | flush () |
| bool | generateByteOrderMark () const |
| int | integerBase () const |
| QLocale | locale () const |
| QTextStream::NumberFlags | numberFlags () const |
| QChar | padChar () const |
| qint64 | pos () const |
| QString | read (qint64 maxlen ) |
| QString | readAll () |
| QString | readLine (qint64 maxlen = 0) |
| bool | readLineInto (QString * line , qint64 maxlen = 0) |
| QTextStream::RealNumberNotation | realNumberNotation () const |
| int | realNumberPrecision () const |
| void | reset () |
| void | resetStatus () |
| bool | seek (qint64 pos ) |
| void | setAutoDetectUnicode (bool enabled ) |
| void | setCodec (QTextCodec * codec ) |
| void | setCodec (const char * codecName ) |
| void | setDevice (QIODevice * device ) |
| void | setFieldAlignment (QTextStream::FieldAlignment mode ) |
| void | setFieldWidth (int width ) |
| void | setGenerateByteOrderMark (bool generate ) |
| void | setIntegerBase (int base ) |
| void | setLocale (const QLocale & locale ) |
| void | setNumberFlags (QTextStream::NumberFlags flags ) |
| void | setPadChar (QChar ch ) |
| void | setRealNumberNotation (QTextStream::RealNumberNotation notation ) |
| void | setRealNumberPrecision (int precision ) |
| void | setStatus (QTextStream::Status status ) |
| void | setString (QString * string , QIODevice::OpenMode openMode = QIODevice::ReadWrite) |
| void | skipWhiteSpace () |
| QTextStream::Status | status () const |
| QString * | string () const |
| QTextStream & | operator<< (QChar c ) |
| QTextStream & | operator<< (char c ) |
| QTextStream & | operator<< (short i ) |
| QTextStream & | operator<< (unsigned short i ) |
| QTextStream & | operator<< (int i ) |
| QTextStream & | operator<< (unsigned int i ) |
| QTextStream & | operator<< (long i ) |
| QTextStream & | operator<< (unsigned long i ) |
| QTextStream & | operator<< (qlonglong i ) |
| QTextStream & | operator<< (qulonglong i ) |
| QTextStream & | operator<< (float f ) |
| QTextStream & | operator<< (double f ) |
| QTextStream & | operator<< (const QString & string ) |
| QTextStream & | operator<< (QStringView string ) |
| QTextStream & | operator<< (QLatin1String string ) |
| QTextStream & | operator<< (const QStringRef & string ) |
| QTextStream & | operator<< (const QByteArray & array ) |
| QTextStream & | operator<< (const char * string ) |
| QTextStream & | operator<< (const void * ptr ) |
| QTextStream & | operator>> (QChar & c ) |
| QTextStream & | operator>> (char & c ) |
| QTextStream & | operator>> (short & i ) |
| QTextStream & | operator>> (unsigned short & i ) |
| QTextStream & | operator>> (int & i ) |
| QTextStream & | operator>> (unsigned int & i ) |
| QTextStream & | operator>> (long & i ) |
| QTextStream & | operator>> (unsigned long & i ) |
| QTextStream & | operator>> (qlonglong & i ) |
| QTextStream & | operator>> (qulonglong & i ) |
| QTextStream & | operator>> (float & f ) |
| QTextStream & | operator>> (double & f ) |
| QTextStream & | operator>> (QString & str ) |
| QTextStream & | operator>> (QByteArray & array ) |
| QTextStream & | operator>> (char * c ) |
| QTextStream & | bin (QTextStream & stream ) |
| QTextStream & | bom (QTextStream & stream ) |
| QTextStream & | center (QTextStream & stream ) |
| QTextStream & | dec (QTextStream & stream ) |
| QTextStream & | endl (QTextStream & stream ) |
| QTextStream & | fixed (QTextStream & stream ) |
| QTextStream & | flush (QTextStream & stream ) |
| QTextStream & | forcepoint (QTextStream & stream ) |
| QTextStream & | forcesign (QTextStream & stream ) |
| QTextStream & | hex (QTextStream & stream ) |
| QTextStream & | left (QTextStream & stream ) |
| QTextStream & | lowercasebase (QTextStream & stream ) |
| QTextStream & | lowercasedigits (QTextStream & stream ) |
| QTextStream & | noforcepoint (QTextStream & stream ) |
| QTextStream & | noforcesign (QTextStream & stream ) |
| QTextStream & | noshowbase (QTextStream & stream ) |
| QTextStream & | oct (QTextStream & stream ) |
| QTextStreamManipulator | qSetFieldWidth (int width ) |
| QTextStreamManipulator | qSetPadChar (QChar ch ) |
| QTextStreamManipulator | qSetRealNumberPrecision (int precision ) |
| QTextStream & | reset (QTextStream & stream ) |
| QTextStream & | right (QTextStream & stream ) |
| QTextStream & | scientific (QTextStream & stream ) |
| QTextStream & | showbase (QTextStream & stream ) |
| QTextStream & | uppercasebase (QTextStream & stream ) |
| QTextStream & | uppercasedigits (QTextStream & stream ) |
| QTextStream & | ws (QTextStream & stream ) |
The QTextStream class provides a convenient interface for reading and writing text.
QTextStream can operate on a QIODevice , QByteArray 或 QString 。使用 QTextStream 's streaming operators, you can conveniently read and write words, lines and numbers. For generating text, QTextStream supports formatting options for field padding and alignment, and formatting of numbers. Example:
QFile data("output.txt"); if (data.open(QFile::WriteOnly | QFile::Truncate)) { QTextStream out(&data); out << "Result: " << qSetFieldWidth(10) << left << 3.14 << 2.7; // writes "Result: 3.14 2.7 " }
It's also common to use QTextStream to read console input and write console output. QTextStream is locale aware, and will automatically decode standard input using the correct codec. Example:
QTextStream stream(stdin); QString line; while (stream.readLineInto(&line)) { ... }
Besides using QTextStream 's constructors, you can also set the device or string QTextStream operates on by calling setDevice () 或 setString ()。可以尋址到位置通過調用 seek (),和 atEnd () 將返迴 true 當沒有剩餘數據要讀取時。若調用 flush (), QTextStream will empty all data from its write buffer into the device and call flush () 在設備。
在內部, QTextStream uses a Unicode based buffer, and QTextCodec 用於 QTextStream to automatically support different character sets. By default, QTextCodec::codecForLocale () is used for reading and writing, but you can also set the codec by calling setCodec (). Automatic Unicode detection is also supported. When this feature is enabled (the default behavior), QTextStream will detect the UTF-16 or the UTF-32 BOM (Byte Order Mark) and switch to the appropriate UTF codec when reading. QTextStream does not write a BOM by default, but you can enable this by calling setGenerateByteOrderMark (true). When QTextStream operates on a QString directly, the codec is disabled.
There are three general ways to use QTextStream when reading text files:
由於文本流使用緩衝,不應該使用超類實現從流讀取。例如,若擁有 QFile 並直接讀取自它使用 QFile::readLine () 而不是使用流,文本流的內部位置將不同步於文件位置。
By default, when reading numbers from a stream of text, QTextStream will automatically detect the number's base representation. For example, if the number starts with "0x", it is assumed to be in hexadecimal form. If it starts with the digits 1-9, it is assumed to be in decimal form, and so on. You can set the integer base, thereby disabling the automatic detection, by calling setIntegerBase ()。範例:
QTextStream in("0x50 0x20"); int firstNumber, secondNumber; in >> firstNumber; // firstNumber == 80 in >> dec >> secondNumber; // secondNumber == 0 char ch; in >> ch; // ch == 'x'
QTextStream supports many formatting options for generating text. You can set the field width and pad character by calling setFieldWidth () 和 setPadChar ()。使用 setFieldAlignment () 以設置每個字段內的對齊方式。對於實數,調用 setRealNumberNotation () 和 setRealNumberPrecision () 以設置錶示法 ( SmartNotation , ScientificNotation , FixedNotation ) 及生成數字的位數精度。一些額外數字格式化選項也是可用的透過 setNumberFlags ().
像
<iostream>
in the standard C++ library,
QTextStream
also defines several global manipulator functions:
此外,Qt 提供瞭 3 個接受參數的全局操縱符: qSetFieldWidth (), qSetPadChar (),和 qSetRealNumberPrecision ().
另請參閱 QDataStream , QIODevice , QFile , QBuffer , QTcpSocket ,和 文本編解碼器範例 .
此枚舉指定如何對齊字段中的文本,當字段比占據文本更寬時。
| 常量 | 值 | 描述 |
|---|---|---|
QTextStream::AlignLeft
|
0
|
鋪墊在字段右側。 |
QTextStream::AlignRight
|
1
|
鋪墊在字段左側。 |
QTextStream::AlignCenter
|
2
|
鋪墊在字段的兩側。 |
QTextStream::AlignAccountingStyle
|
3
|
如同 AlignRight,除刷新數字符號左側外。 |
另請參閱 setFieldAlignment ().
此枚舉指定可以設置的各種標誌能影響輸齣對於整數,
float
,和
double
。
| 常量 | 值 | 描述 |
|---|---|---|
QTextStream::ShowBase
|
0x1
|
展示作為前綴的基,若基為 16 (0x)、8 (0)、或 2 (0b)。 |
QTextStream::ForcePoint
|
0x2
|
在數字中始終放置小數分隔符,即使沒有小數。 |
QTextStream::ForceSign
|
0x4
|
在數字中始終放置符號,即使為正數。 |
QTextStream::UppercaseBase
|
0x8
|
使用大寫版本的基前綴 (0X、0B)。 |
QTextStream::UppercaseDigits
|
0x10
|
數字 10-35 使用大寫字母錶達,而不是小寫。 |
NumberFlags 類型是 typedef 對於 QFlags <NumberFlag>。它存儲 NumberFlag 值的 OR 組閤。
另請參閱 setNumberFlags ().
此枚舉指定使用哪種錶示法錶達
float
and
double
以字符串形式。
| 常量 | 值 | 描述 |
|---|---|---|
QTextStream::ScientificNotation
|
2
|
科學錶示法 (
printf()
's
%e
標誌)。
|
QTextStream::FixedNotation
|
1
|
定點錶示法 (
printf()
's
%f
標誌)。
|
QTextStream::SmartNotation
|
0
|
科學 (或定點) 錶示法,從屬哪種更有意義 (
printf()
's
%g
標誌)。
|
另請參閱 setRealNumberNotation ().
此枚舉描述文本流的當前狀態。
| 常量 | 值 | 描述 |
|---|---|---|
QTextStream::Ok
|
0
|
文本流運轉正常。 |
QTextStream::ReadPastEnd
|
1
|
文本流已讀取過瞭底層設備的數據末尾。 |
QTextStream::ReadCorruptData
|
2
|
文本流有讀取被破壞數據。 |
QTextStream::WriteFailed
|
3
|
文本流無法寫入到底層設備。 |
另請參閱 status ().
構造 QTextStream . Before you can use it for reading or writing, you must assign a device or a string.
另請參閱 setDevice () 和 setString ().
構造 QTextStream that operates on device .
構造 QTextStream that operates on fileHandle ,使用 openMode 定義打開方式。在內部, QFile 被創建以處理 FILE 指針。
此構造函數很有用,對於直接工作於基於公共 FILE 的輸入和輸齣流:stdin、stdout 和 stderr。範例:
QString str; QTextStream in(stdin); in >> str;
構造 QTextStream that operates on string ,使用 openMode 定義打開方式。
構造 QTextStream that operates on array ,使用 openMode 定義打開方式。在內部,數組的包裹是通過 QBuffer .
構造 QTextStream that operates on array ,使用 openMode 定義打開方式。以隻讀方式訪問數組,不管值 openMode .
此構造函數操控常量字符串很方便。範例:
int main(int argc, char *argv[]) { // read numeric arguments (123, 0x20, 4.5...) for (int i = 1; i < argc; ++i) { int number; QTextStream in(argv[i]); in >> number; ... } }
[虛擬]
QTextStream::
~QTextStream
()
銷毀 QTextStream .
若流運轉於設備, flush () 會被隱式調用。否則,設備不受影響。
返迴
true
若沒有更多數據能讀取自
QTextStream
;否則返迴
false
。這類似於,但不同於調用
QIODevice::atEnd
(),因為
QTextStream
還考慮其內部 Unicode 緩衝。
返迴
true
若啓用瞭自動 Unicode 檢測,否則返迴
false
。默認啓用自動 Unicode 檢測。
另請參閱 setAutoDetectUnicode (), setCodec (),和 QTextCodec::codecForUtfText ().
Returns the codec that is current assigned to the stream.
另請參閱 setCodec (), setAutoDetectUnicode (),和 locale ().
返迴被當前設備關聯的 QTextStream , or 0 if no device has been assigned.
另請參閱 setDevice () 和 string ().
返迴當前字段的對齊。
另請參閱 setFieldAlignment () 和 fieldWidth ().
返迴當前字段的寬度。
另請參閱 setFieldWidth ().
刷新等待寫入設備的任何緩衝數據。
若 QTextStream 運轉於字符串,此函數什麼都不做。
返迴
true
if
QTextStream
is set to generate the UTF BOM (Byte Order Mark) when using a UTF codec; otherwise returns
false
。默認情況下,UTF BOM (字節序標記) 生成被設為 false。
另請參閱 setGenerateByteOrderMark ().
返迴整數的當前基。0 意味著檢測基當讀取時,或 10 (十進製) 當生成數字時。
另請參閱 setIntegerBase (), QString::number (),和 numberFlags ().
返迴用於此流的區域設置。默認區域設置為 C。
該函數在 Qt 4.5 引入。
另請參閱 setLocale ().
返迴當前數字的標誌。
另請參閱 setNumberFlags (), integerBase (),和 realNumberNotation ().
返迴當前鋪墊的字符。
另請參閱 setPadChar () 和 setFieldWidth ().
返迴對應流當前位置的設備位置,或 -1 若齣現錯誤 (如:若沒有設備/字符串,或若存在設備錯誤)。
因為 QTextStream 有緩衝,此函數可能必須尋址設備以重構有效設備位置。此操作會很昂貴,所以,可能想要避免在緊密循環中調用此函數。
該函數在 Qt 4.2 引入。
另請參閱 seek ().
讀取最多 maxlen 字符從流,並返迴讀取數據按 QString .
該函數在 Qt 4.1 引入。
另請參閱 readAll (), readLine (),和 QIODevice::read ().
讀取流的整個內容,並返迴它按 QString 。避免使用此函數,當操控大文件時。因為 , 它會消耗大量內存。
調用 readLine() is better if you do not know how much data is available.
另請參閱 readLine ().
從流讀取 1 行文本,並返迴它按 QString 。最大允許行長度被設為 maxlen 。若流包含的行長於這,則分割行後於 maxlen 字符並以部分形式返迴。
若 maxlen 為 0,行可以是任意長度。
返迴行沒有結尾 (\n 或 \r\n) 行尾字符,所以調用 QString::trimmed () 可能不必要。
若流已讀取到 EOF (文件末尾),readLine() 返迴 null QString 。對於字符串 (或支持字符串的設備),可以明確測試流是否結束使用 atEnd ().
另請參閱 readAll () 和 QIODevice::readLine ().
從流讀取 1 行文本到 line 。若 line is 0, the read line is not stored.
最大允許行長度被設為 maxlen 。若流包含的行長於這,則分割行後於 maxlen 字符並以部分形式返迴。
若 maxlen 為 0,行可以是任意長度。
結果行沒有結尾 (\n 或 \r\n) 行尾字符,所以調用 QString::trimmed () 可能不必要。
若 line 有足夠容量容納即將讀取的數據;此函數可能不需要分配新內存。因此,它可以更快相比 readLine ().
返迴
false
若流已讀取到 EOF (文件末尾) 或齣現錯誤;否則返迴
true
。內容在
line
在調用前被丟棄,在任何情況下。
該函數在 Qt 5.5 引入。
另請參閱 readAll () 和 QIODevice::readLine ().
返迴當前實數錶示法。
另請參閱 setRealNumberNotation (), realNumberPrecision (), numberFlags (),和 integerBase ().
返迴當前實數的精度,或數字的小數位數, QTextStream will write when generating real numbers.
另請參閱 setRealNumberPrecision (), setRealNumberNotation (), realNumberNotation (), numberFlags (),和 integerBase ().
重置 QTextStream 的格式化選項,將之還原到其原始構造狀態。設備、字符串及任何緩衝數據,保持不變。
重置文本流的狀態。
該函數在 Qt 4.1 引入。
另請參閱 QTextStream::Status , status (),和 setStatus ().
尋址到位置
pos
在設備中。返迴
true
當成功時;否則返迴
false
.
若 enabled 為 True, QTextStream 將試圖通過窺視流數據以檢測 Unicode 編碼,看是否可以找到 UTF-8、UTF-16 或 UTF-32 BOM (字節序標記)。若有找到此標記, QTextStream will replace the current codec with the UTF codec.
此函數可以一起使用與 setCodec (). It is common to set the codec to UTF-8, and then enable UTF-16 detection.
另請參閱 autoDetectUnicode (), setCodec (),和 QTextCodec::codecForUtfText ().
Sets the codec for this stream to codec . The codec is used for decoding any data that is read from the assigned device, and for encoding any data that is written. By default, QTextCodec::codecForLocale () is used, and automatic unicode detection is enabled.
若 QTextStream 運轉於字符串,此函數什麼都不做。
警告: If you call this function while the text stream is reading from an open sequential socket, the internal buffer may still contain text decoded using the old codec.
另請參閱 codec (), setAutoDetectUnicode (),和 setLocale ().
Sets the codec for this stream to the
QTextCodec
為指定編碼通過
codecName
。常見值對於
codecName
包括 ISO 8859-1、UTF-8 及 UTF-16。若編碼無法識彆,則什麼都不發生。
範例:
QTextStream out(&file); out.setCodec("UTF-8");
另請參閱 QTextCodec::codecForName () 和 setLocale ().
把當前設備設為 device 。若已經有賦值設備, QTextStream 將調用 flush () 在替換舊設備前。
注意: This function resets locale to the default locale ('C') and codec to the default codec, QTextCodec::codecForLocale ().
另請參閱 device () 和 setString ().
把字段對齊方式設為 mode 。當一起用於 setFieldWidth (),此函數允許生成對齊到左、對齊到右、或居中對齊的格式化輸齣文本。
另請參閱 fieldAlignment () 和 setFieldWidth ().
把當前字段寬度設為 width 。若 width 為 0 (默認),字段寬度等於生成文本長度。
注意: 字段寬度適用於追加到此流的每個元素,在調用此函數後 (如:它還鋪墊 endl)。此行為不同於 STL (標準模闆庫) 類似類,在 STL,字段寬度隻適用於下一元素。
另請參閱 fieldWidth () 和 setPadChar ().
若 generate is true and a UTF codec is used, QTextStream 將插入 BOM (字節序標記) 在把任何數據寫入設備前。若 generate 為 False,將不插入 BOM。必須在寫入任何數據之前,調用此函數。否則,什麼都不做。
另請參閱 generateByteOrderMark () 和 bom ().
把整數的基設為 base ,用於讀取和生成數字兩者。 base 可以為 2 (二進製)、8 (八進製)、10 (十進製) 或 16 (十六進製)。若 base 為 0, QTextStream 將試圖檢測基通過審查流中的數據。當生成數字時, QTextStream 假定基為 10 除非有明確設置基。
另請參閱 integerBase (), QString::number (),和 setNumberFlags ().
把用於此流的區域設置設為 locale 。指定的區域設置用於數字及其字符串錶示形式之間的轉換。
默認區域設置為 C 且是特殊情況 - 不使用韆位組分隔符,齣於嚮後兼容原因。
該函數在 Qt 4.5 引入。
另請參閱 locale ().
把當前數字標誌設為 flags . flags 是一組標誌來自 NumberFlag enum, and describes options for formatting generated code (e.g., whether or not to always write the base or sign of a number).
另請參閱 numberFlags (), setIntegerBase (),和 setRealNumberNotation ().
把鋪墊字符設為 ch 。默認值為 ASCII 空格字符 ' ',或 QChar (0x20)。此字符用於填充字段中的空格,當生成文本時。
範例:
QString s; QTextStream out(&s); out.setFieldWidth(10); out.setFieldAlignment(QTextStream::AlignCenter); out.setPadChar('-'); out << "Qt" << "rocks!";
字符串
s
包含:
----Qt------rocks!--
另請參閱 padChar () 和 setFieldWidth ().
把實數錶示法設為 notation ( SmartNotation , FixedNotation , ScientificNotation )。當讀取並生成數字時, QTextStream 使用此值來檢測實數的格式。
另請參閱 realNumberNotation (), setRealNumberPrecision (), setNumberFlags (),和 setIntegerBase ().
把實數的精度設為 precision . This value describes the number of fraction digits QTextStream should write when generating real numbers.
精度不可以為負值。默認值為 6。
另請參閱 realNumberPrecision () 和 setRealNumberNotation ().
把文本流的狀態設為 status 給定。
忽略後續 setStatus() 調用,直到 resetStatus () 被調用。
該函數在 Qt 4.1 引入。
另請參閱 Status , status (),和 resetStatus ().
將當前字符串設為 string ,使用給定 openMode 。若已經有賦值設備, QTextStream 將調用 flush () 在替換它前。
另請參閱 string () 和 setDevice ().
Reads and discards whitespace from the stream until either a non-space character is detected, or until atEnd () returns true. This function is useful when reading a stream character by character.
空白字符是所有字符對於那些
QChar::isSpace
() 返迴
true
.
另請參閱 operator>> ().
返迴文本流的狀態。
另請參閱 QTextStream::Status , setStatus (),和 resetStatus ().
返迴的當前字符串被賦值給 QTextStream , or 0 if no string has been assigned.
另請參閱 setString () 和 device ().
寫入字符 c 到流,然後返迴引用針對 QTextStream .
另請參閱 setFieldWidth ().
這是重載函數。
轉換 c 從 ASCII 到 QChar ,然後將它寫入流。
寫入整數數字 i 到流,然後返迴引用針對 QTextStream . By default, the number is stored in decimal form, but you can also set the base by calling setIntegerBase ().
另請參閱 setFieldWidth () 和 setNumberFlags ().
這是重載函數。
寫入無符號短整數 i 到流。
這是重載函數。
寫入有符號整數 i 到流。
這是重載函數。
寫入無符號整數 i 到流。
這是重載函數。
寫入有符號 long i 到流。
這是重載函數。
寫入無符號 long i 到流。
這是重載函數。
寫入 qlonglong i 到流。
這是重載函數。
寫入 qulonglong i 到流。
寫入實數 f 到流,然後返迴引用針對 QTextStream 。默認情況下, QTextStream 存儲它使用 SmartNotation , with up to 6 digits of precision. You can change the textual representation QTextStream will use for real numbers by calling setRealNumberNotation (), setRealNumberPrecision () 和 setNumberFlags ().
另請參閱 setFieldWidth (), setRealNumberNotation (), setRealNumberPrecision (),和 setNumberFlags ().
這是重載函數。
寫入 double f 到流。
寫入字符串 string 到流,並返迴引用針對 QTextStream . The string is first encoded using the assigned codec (the default codec is QTextCodec::codecForLocale ()) before it is written to the stream.
另請參閱 setFieldWidth () 和 setCodec ().
這是重載函數。
寫入 string 到流,並返迴引用針對 QTextStream .
該函數在 Qt 5.12 引入。
這是重載函數。
寫入 string 到流,並返迴引用針對 QTextStream .
這是重載函數。
寫入 string 到流,並返迴引用針對 QTextStream .
該函數在 Qt 5.6 引入。
這是重載函數。
寫入 array 到流。內容對於 array 的轉換是采用 QString::fromUtf8 ().
這是重載函數。
寫入常量字符串指嚮通過 string 到流。 string is assumed to be in ISO-8859-1 encoding. This operator is convenient when working with constant string data. Example:
QTextStream out(stdout); out << "Qt rocks!" << endl;
警告: QTextStream assumes that string points to a string of text, terminated by a '\0' character. If there is no terminating '\0' character, your application may crash.
這是重載函數。
寫入 ptr 到流以具有基的十六進製數形式。
從流讀取字符並把它存儲在 c . Returns a reference to the QTextStream , so several operators can be nested. Example:
QTextStream in(file); QChar ch1, ch2, ch3; in >> ch1 >> ch2 >> ch3;
空白 not 跳過。
這是重載函數。
從流讀取字符並把它存儲在 c . The character from the stream is converted to ISO-5589-1 before it is stored.
另請參閱 QChar::toLatin1 ().
讀取整數從流並把它存儲在 i ,然後返迴引用針對 QTextStream 。把數字鑄造成正確類型,在存儲它之前。若在流中未檢測到數字, i 被設為 0。
默認情況下, QTextStream 將試圖使用下列規則以檢測數字的基:
| 前綴 | 基 |
|---|---|
| 0b 或 0B | 2 (二進製) |
| "0" followed by "0-7" | 8 (八進製) |
| "0" otherwise | 10 (十進製) |
| 0x 或 0X | 16 (十六進製) |
| 1-9 | 10 (十進製) |
通過調用 setIntegerBase (), you can specify the integer base explicitly. This will disable the auto-detection, and speed up QTextStream slightly.
跳過前導空白。
這是重載函數。
Stores the integer in the unsigned short i .
這是重載函數。
Stores the integer in the signed int i .
這是重載函數。
Stores the integer in the unsigned int i .
這是重載函數。
Stores the integer in the signed long i .
這是重載函數。
Stores the integer in the unsigned long i .
這是重載函數。
Stores the integer in the qlonglong i .
這是重載函數。
Stores the integer in the qulonglong i .
Reads a real number from the stream and stores it in f ,然後返迴引用針對 QTextStream . The number is cast to the correct type. If no real number is detect on the stream, f is set to 0.0.
As a special exception, QTextStream allows the strings "nan" and "inf" to represent NAN and INF floats or doubles.
跳過前導空白。
這是重載函數。
把實數存儲在 double f .
Reads a word from the stream and stores it in
str
, then returns a reference to the stream. Words are separated by whitespace (i.e., all characters for which
QChar::isSpace
() 返迴
true
).
跳過前導空白。
這是重載函數。
Converts the word to ISO-8859-1, then stores it in array .
另請參閱 QString::toLatin1 ().
這是重載函數。
Stores the word in 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 c points to a buffer with enough space to hold the word. If the buffer is too small, your application may crash.
若可能的話,使用 QByteArray 操作符代替。
調用 QTextStream::setIntegerBase (2) 在 stream 並返迴 stream .
另請參閱 oct (), dec (), hex (),和 QTextStream 操作符 .
切換插入的 BOM (字節序標記) 在 stream 當 QTextStream is used with a UTF codec.
另請參閱 QTextStream::setGenerateByteOrderMark () 和 QTextStream 操作符 .
調用 QTextStream::setFieldAlignment ( QTextStream::AlignCenter ) 在 stream 並返迴 stream .
另請參閱 left (), right (),和 QTextStream 操作符 .
調用 QTextStream::setIntegerBase (10) 在 stream 並返迴 stream .
另請參閱 bin (), oct (), hex (),和 QTextStream 操作符 .
寫入 \n 到 stream 並刷新流。
相當於
stream << '\n' << flush;
注意:在 Windows,所有 \n 字符被寫成 \r\n 若 QTextStream 's device or string is opened using the QIODevice::Text 標誌。
另請參閱 flush (), reset (),和 QTextStream 操作符 .
調用 QTextStream::setRealNumberNotation ( QTextStream::FixedNotation ) 在 stream 並返迴 stream .
另請參閱 scientific () 和 QTextStream 操作符 .
調用 QTextStream::flush () 在 stream 並返迴 stream .
另請參閱 endl (), reset (),和 QTextStream 操作符 .
調用 QTextStream::setNumberFlags ( QTextStream::numberFlags () | QTextStream::ForcePoint ) 在 stream 並返迴 stream .
另請參閱 noforcepoint (), forcesign (), showbase (),和 QTextStream 操作符 .
調用 QTextStream::setNumberFlags ( QTextStream::numberFlags () | QTextStream::ForceSign ) 在 stream 並返迴 stream .
另請參閱 noforcesign (), forcepoint (), showbase (),和 QTextStream 操作符 .
調用 QTextStream::setIntegerBase (16) 在 stream 並返迴 stream .
注意: 十六進製修飾符隻可以用於寫入到流。
另請參閱 bin (), oct (), dec (),和 QTextStream 操作符 .
調用 QTextStream::setFieldAlignment ( QTextStream::AlignLeft ) 在 stream 並返迴 stream .
另請參閱 right (), center (),和 QTextStream 操作符 .
調用 QTextStream::setNumberFlags ( QTextStream::numberFlags () & ~ QTextStream::UppercaseBase ) 在 stream 並返迴 stream .
另請參閱 uppercasebase (), lowercasedigits (),和 QTextStream 操作符 .
調用 QTextStream::setNumberFlags ( QTextStream::numberFlags () & ~ QTextStream::UppercaseDigits ) 在 stream 並返迴 stream .
另請參閱 uppercasedigits (), lowercasebase (),和 QTextStream 操作符 .
調用 QTextStream::setNumberFlags ( QTextStream::numberFlags () & ~ QTextStream::ForcePoint ) 在 stream 並返迴 stream .
另請參閱 forcepoint (), noforcesign (), noshowbase (),和 QTextStream 操作符 .
調用 QTextStream::setNumberFlags ( QTextStream::numberFlags () & ~ QTextStream::ForceSign ) 在 stream 並返迴 stream .
另請參閱 forcesign (), noforcepoint (), noshowbase (),和 QTextStream 操作符 .
調用 QTextStream::setNumberFlags ( QTextStream::numberFlags () & ~ QTextStream::ShowBase ) 在 stream 並返迴 stream .
另請參閱 showbase (), noforcesign (), noforcepoint (),和 QTextStream 操作符 .
調用 QTextStream::setIntegerBase (8) 在 stream 並返迴 stream .
另請參閱 bin (), dec (), hex (),和 QTextStream 操作符 .
相當於 QTextStream::setFieldWidth ( width ).
相當於 QTextStream::setPadChar ( ch ).
相當於 QTextStream::setRealNumberPrecision ( precision ).
調用 QTextStream::reset () 在 stream 並返迴 stream .
另請參閱 flush () 和 QTextStream 操作符 .
調用 QTextStream::setFieldAlignment ( QTextStream::AlignRight ) 在 stream 並返迴 stream .
另請參閱 left (), center (),和 QTextStream 操作符 .
調用 QTextStream::setRealNumberNotation ( QTextStream::ScientificNotation ) 在 stream 並返迴 stream .
另請參閱 fixed () 和 QTextStream 操作符 .
調用 QTextStream::setNumberFlags ( QTextStream::numberFlags () | QTextStream::ShowBase ) 在 stream 並返迴 stream .
另請參閱 noshowbase (), forcesign (), forcepoint (),和 QTextStream 操作符 .
調用 QTextStream::setNumberFlags ( QTextStream::numberFlags () | QTextStream::UppercaseBase ) 在 stream 並返迴 stream .
另請參閱 lowercasebase (), uppercasedigits (),和 QTextStream 操作符 .
調用 QTextStream::setNumberFlags ( QTextStream::numberFlags () | QTextStream::UppercaseDigits ) 在 stream 並返迴 stream .
另請參閱 lowercasedigits (), uppercasebase (),和 QTextStream 操作符 .
調用 skipWhiteSpace() on stream 並返迴 stream .
另請參閱 QTextStream 操作符 .