QTextStream 類提供用於讀寫文本的方便接口。 更多...
| 頭: |
#include <QTextStream>
|
| CMake: |
find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
|
| qmake: |
QT += core
|
| 繼承: | QIODeviceBase |
注意: 此類的所有函數 可重入 .
| 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 , QIODeviceBase::OpenMode openMode = ReadWrite) | |
| QTextStream (QByteArray * array , QIODeviceBase::OpenMode openMode = ReadWrite) | |
| QTextStream (QString * string , QIODeviceBase::OpenMode openMode = ReadWrite) | |
| QTextStream (const QByteArray & array , QIODeviceBase::OpenMode openMode = ReadOnly) | |
| virtual | ~QTextStream () |
| bool | atEnd () const |
| bool | autoDetectUnicode () const |
| QIODevice * | device () const |
| QStringConverter::Encoding | encoding () 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 | setDevice (QIODevice * device ) |
| void | setEncoding (QStringConverter::Encoding encoding ) |
| 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 , QIODeviceBase::OpenMode openMode = ReadWrite) |
| void | skipWhiteSpace () |
| QTextStream::Status | status () const |
| QString * | string () const |
| QTextStream & | operator<< (QChar c ) |
| QTextStream & | operator<< (const QString & string ) |
| QTextStream & | operator<< (float f ) |
| QTextStream & | operator<< (short i ) |
| QTextStream & | operator<< (QLatin1StringView string ) |
| QTextStream & | operator<< (QStringView string ) |
| QTextStream & | operator<< (char c ) |
(since 6.3.1)
QTextStream &
|
operator<< (char16_t c ) |
| QTextStream & | operator<< (const QByteArray & array ) |
| QTextStream & | operator<< (const char * string ) |
| QTextStream & | operator<< (const void * ptr ) |
| QTextStream & | operator<< (double f ) |
| QTextStream & | operator<< (int i ) |
| QTextStream & | operator<< (long i ) |
| QTextStream & | operator<< (qlonglong i ) |
| QTextStream & | operator<< (qulonglong i ) |
| QTextStream & | operator<< (unsigned int i ) |
| QTextStream & | operator<< (unsigned long i ) |
| QTextStream & | operator<< (unsigned short i ) |
| QTextStream & | operator>> (QChar & c ) |
| QTextStream & | operator>> (QString & str ) |
| QTextStream & | operator>> (float & f ) |
| QTextStream & | operator>> (short & i ) |
| QTextStream & | operator>> (QByteArray & array ) |
| QTextStream & | operator>> (char & c ) |
| QTextStream & | operator>> (char * c ) |
(從 6.4 起)
QTextStream &
|
operator>> (char16_t & c ) |
| QTextStream & | operator>> (double & f ) |
| QTextStream & | operator>> (int & i ) |
| QTextStream & | operator>> (long & i ) |
| QTextStream & | operator>> (qlonglong & i ) |
| QTextStream & | operator>> (qulonglong & i ) |
| QTextStream & | operator>> (unsigned int & i ) |
| QTextStream & | operator>> (unsigned long & i ) |
| QTextStream & | operator>> (unsigned short & i ) |
| QTextStreamManipulator | qSetFieldWidth (int width ) |
| QTextStreamManipulator | qSetPadChar (QChar ch ) |
| QTextStreamManipulator | qSetRealNumberPrecision (int precision ) |
QTextStream 可以運轉於 QIODevice , QByteArray 或 QString 。使用 QTextStream 的流運算符,可以方便地讀寫單詞、行及數字。為生成文本,QTextStream 支持用於字段鋪墊和對齊的格式化選項、及數字格式化。範例:
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 " }
使用 QTextStream 讀取控製颱輸入,並寫入控製颱輸齣也很常見。QTextStream 感知區域設置,且會使用正確編碼自動解碼 stdin (標準輸入)。範例:
QTextStream stream(stdin); QString line; while (stream.readLineInto(&line)) { ... }
除使用 QTextStream 構造函數外,還可以設置操作設備 (或字符串) 的 QTextStream 通過調用 setDevice () 或 setString ()。可以尋址到位置通過調用 seek (),和 atEnd () 將返迴 true 當沒有剩餘數據要讀取時。若調用 flush (),QTextStream 將清空其寫入緩衝中的所有數據並調用 flush () 在設備。
在內部,QTextStream 使用 Unicode 基緩衝,和 QStringConverter 用於 QTextStream 以自動支持不同編碼。默認情況下,UTF-8 用於讀寫,但也可以設置編碼通過調用 setEncoding ()。自動 Unicode 檢測也支持。當啓用此特徵 (默認行為) 時,QTextStream 將檢測 UTF-8、UTF-16 或 UTF-32 BOM (字節序標記),並在讀取時切換到適當 UTF 編碼。默認情況下,QTextStream 不會寫入 BOM,但可以啓用這通過調用 setGenerateByteOrderMark (true)。當 QTextStream 運轉於 QString 直接,禁用編碼。
使用 QTextStream 有 3 種一般辦法,當讀取文本文件時:
由於文本流使用緩衝,不應該使用超類實現從流讀取。例如,若擁有 QFile 並直接讀取自它使用 QFile::readLine () 而不是使用流,文本流的內部位置將不同步於文件位置。
默認情況下,當從文本流讀取數字時,QTextStream 將自動檢測數字的基錶示。例如,若數字以 0x 開始,假定是十六進製形式。若以數字 1-9 開始,假定是十進製形式,依此類推。可以設置整數基,從而禁用自動檢測,通過調用 setIntegerBase ()。範例:
QTextStream in("0x50 0x20"); int firstNumber, secondNumber; in >> firstNumber; // firstNumber == 80 in >> dec >> secondNumber; // secondNumber == 0 char ch; in >> ch; // ch == 'x'
QTextStream 支持用於生成文本的很多格式化選項。可以設置字段寬度,和填充字符通過調用 setFieldWidth () 和 setPadChar ()。使用 setFieldAlignment () 以設置每個字段內的對齊方式。對於實數,調用 setRealNumberNotation () 和 setRealNumberPrecision () 以設置錶示法 ( SmartNotation , ScientificNotation , FixedNotation ) 及生成數字的位數精度。一些額外數字格式化選項也是可用的透過 setNumberFlags ().
像
<iostream>
在標準 C++ 庫,QTextStream 還定義瞭幾個全局操縱器函數:
此外,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。在可以使用它進行讀取 (或寫入) 之前,必須賦值設備 (或字符串)。
另請參閱 setDevice () 和 setString ().
[explicit]
QTextStream::
QTextStream
(
QIODevice
*
device
)
構造 QTextStream 運轉於 device .
[explicit]
QTextStream::
QTextStream
(
FILE
*
fileHandle
,
QIODeviceBase::OpenMode
openMode
= ReadWrite)
構造 QTextStream 運轉於 fileHandle ,使用 openMode 定義打開方式。在內部, QFile 被創建以處理 FILE 指針。
此構造函數很有用,對於直接工作於基於公共 FILE 的輸入和輸齣流:stdin、stdout 和 stderr。範例:
QString str; QTextStream in(stdin); in >> str;
[explicit]
QTextStream::
QTextStream
(
QByteArray
*
array
,
QIODeviceBase::OpenMode
openMode
= ReadWrite)
構造 QTextStream 運轉於 array ,使用 openMode 定義打開方式。在內部,數組的包裹是通過 QBuffer .
[explicit]
QTextStream::
QTextStream
(
QString
*
string
,
QIODeviceBase::OpenMode
openMode
= ReadWrite)
構造 QTextStream 運轉於 string ,使用 openMode 定義打開方式。
[explicit]
QTextStream::
QTextStream
(const
QByteArray
&
array
,
QIODeviceBase::OpenMode
openMode
= ReadOnly)
構造 QTextStream 運轉於 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; ... } }
[virtual noexcept]
QTextStream::
~QTextStream
()
銷毀 QTextStream .
若流運轉於設備, flush () 會被隱式調用。否則,設備不受影響。
返迴
true
若沒有更多數據能讀取自
QTextStream
;否則返迴
false
。這類似於,但不同於調用
QIODevice::atEnd
(),因為
QTextStream
還考慮其內部 Unicode 緩衝。
返迴
true
若啓用瞭自動 Unicode 檢測,否則返迴
false
。默認啓用自動 Unicode 檢測。
另請參閱 setAutoDetectUnicode () 和 setEncoding ().
返迴被當前設備關聯的
QTextStream
,或
nullptr
若沒有設備被賦值。
另請參閱 setDevice () 和 string ().
返迴賦值給流的當前編碼。
另請參閱 setEncoding (), setAutoDetectUnicode (),和 locale ().
返迴當前字段的對齊。
另請參閱 setFieldAlignment () 和 fieldWidth ().
返迴當前字段的寬度。
另請參閱 setFieldWidth ().
刷新等待寫入設備的任何緩衝數據。
若 QTextStream 運轉於字符串,此函數什麼都不做。
返迴
true
if
QTextStream
被設為生成 UTF BOM (字節序標記),當使用 UTF 編碼時;否則返迴
false
。默認情況下,UTF BOM (字節序標記) 生成被設為 false。
另請參閱 setGenerateByteOrderMark ().
返迴整數的當前基。0 意味著檢測基當讀取時,或 10 (十進製) 當生成數字時。
另請參閱 setIntegerBase (), QString::number (),和 numberFlags ().
返迴用於此流的區域設置。默認區域設置為 C。
另請參閱 setLocale ().
返迴當前數字的標誌。
另請參閱 setNumberFlags (), integerBase (),和 realNumberNotation ().
返迴當前鋪墊的字符。
另請參閱 setPadChar () 和 setFieldWidth ().
返迴對應流當前位置的設備位置,或 -1 若齣現錯誤 (如:若沒有設備/字符串,或若存在設備錯誤)。
因為 QTextStream 有緩衝,此函數可能必須尋址設備以重構有效設備位置。此操作會很昂貴,所以,可能想要避免在緊密循環中調用此函數。
另請參閱 seek ().
讀取最多 maxlen 字符從流,並返迴讀取數據按 QString .
另請參閱 readAll (), readLine (),和 QIODevice::read ().
讀取流的整個內容,並返迴它按 QString 。避免使用此函數,當操控大文件時。因為 , 它會消耗大量內存。
調用 readLine () 更好,若不知道有多少數據可用。
另請參閱 readLine ().
從流讀取 1 行文本,並返迴它按 QString 。最大允許行長度被設為 maxlen 。若流包含的行長於這,則分割行後於 maxlen 字符並以部分形式返迴。
若 maxlen 為 0,行可以是任意長度。
返迴行沒有結尾 (\n 或 \r\n) 行尾字符,所以調用 QString::trimmed () 可能不必要。
若流已讀取到 EOF (文件末尾),readLine() 返迴 null QString 。對於字符串 (或支持字符串的設備),可以明確測試流是否結束使用 atEnd ().
另請參閱 readAll () 和 QIODevice::readLine ().
從流讀取 1 行文本到
line
。若
line
is
nullptr
,不存儲讀取行。
最大允許行長度被設為 maxlen 。若流包含的行長於這,則分割行後於 maxlen 字符並以部分形式返迴。
若 maxlen 為 0,行可以是任意長度。
結果行沒有結尾 (\n 或 \r\n) 行尾字符,所以調用 QString::trimmed () 可能不必要。
若 line 有足夠容量容納即將讀取的數據;此函數可能不需要分配新內存。因此,它可以更快相比 readLine ().
返迴
false
若流已讀取到 EOF (文件末尾) 或齣現錯誤;否則返迴
true
。內容在
line
在調用前被丟棄,在任何情況下。
另請參閱 readAll () 和 QIODevice::readLine ().
返迴當前實數錶示法。
另請參閱 setRealNumberNotation (), realNumberPrecision (), numberFlags (),和 integerBase ().
返迴當前實數的精度,或數字的小數位數, QTextStream 將寫入當生成實數 ( FixedNotation , ScientificNotation ),或最大數字的有效位數 ( SmartNotation ).
另請參閱 setRealNumberPrecision (), setRealNumberNotation (), realNumberNotation (), numberFlags (),和 integerBase ().
重置 QTextStream 的格式化選項,將之還原到其原始構造狀態。設備、字符串及任何緩衝數據,保持不變。
重置文本流的狀態。
另請參閱 QTextStream::Status , status (),和 setStatus ().
尋址到位置
pos
在設備中。返迴
true
當成功時;否則返迴
false
.
若 enabled 為 True, QTextStream 將試圖通過窺視流數據以檢測 Unicode 編碼,看是否可以找到 UTF-8、UTF-16 或 UTF-32 BOM (字節序標記)。若有找到此標記, QTextStream 將以 UTF 編碼替換當前編碼。
此函數可以一起使用與 setEncoding ()。常見是把編碼設為 UTF-8,然後啓用 UTF-16 檢測。
另請參閱 autoDetectUnicode () 和 setEncoding ().
把當前設備設為 device 。若已經有賦值設備, QTextStream 將調用 flush () 在替換舊設備前。
注意: 此函數把區域設置重置成 C 默認區域設置,並將編碼重置成 UTF-8 默認編碼。
另請參閱 device () 和 setString ().
把用於此流的編碼設為 encoding 。編碼用於解碼從賦值設備讀取的任何數據,和用於編碼要寫入的任何數據。默認情況下, QStringConverter::Utf8 被使用,並啓用自動 Unicode 檢測。
若 QTextStream 運轉於字符串,此函數什麼都不做。
警告: 若調用此函數 (當文本流正從打開的順序套接字讀取時),內部緩衝可能仍包含使用舊編碼的解碼文本。
另請參閱 encoding (), setAutoDetectUnicode (),和 setLocale ().
把字段對齊方式設為 mode 。當一起用於 setFieldWidth (),此函數允許生成對齊到左、對齊到右、或居中對齊的格式化輸齣文本。
另請參閱 fieldAlignment () 和 setFieldWidth ().
把當前字段寬度設為 width 。若 width 為 0 (默認),字段寬度等於生成文本長度。
注意: 字段寬度適用於追加到此流的每個元素,在調用此函數後 (如:它還鋪墊 endl)。此行為不同於 STL (標準模闆庫) 類似類,在 STL,字段寬度隻適用於下一元素。
另請參閱 fieldWidth () 和 setPadChar ().
若 generate 為 true 並使用 UTF 編碼, QTextStream 將插入 BOM (字節序標記) 在把任何數據寫入設備前。若 generate 為 False,將不插入 BOM。必須在寫入任何數據之前,調用此函數。否則,什麼都不做。
另請參閱 generateByteOrderMark () 和 bom ().
把整數的基設為 base ,用於讀取和生成數字兩者。 base 可以為 2 (二進製)、8 (八進製)、10 (十進製) 或 16 (十六進製)。若 base 為 0, QTextStream 將試圖檢測基通過審查流中的數據。當生成數字時, QTextStream 假定基為 10 除非有明確設置基。
另請參閱 integerBase (), QString::number (),和 setNumberFlags ().
把用於此流的區域設置設為 locale 。指定的區域設置用於數字及其字符串錶示形式之間的轉換。
默認區域設置為 C 且是特殊情況 - 不使用韆位組分隔符,齣於嚮後兼容原因。
另請參閱 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 ( FixedNotation , ScientificNotation ),或最大數字的有效位數 ( SmartNotation ).
精度不可以為負值。默認值為 6。
另請參閱 realNumberPrecision () 和 setRealNumberNotation ().
把文本流的狀態設為 status 給定。
忽略後續 setStatus() 調用,直到 resetStatus () 被調用。
另請參閱 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
,或
nullptr
若沒有賦值字符串。
另請參閱 setString () 和 device ().
寫入字符 c 到流,然後返迴引用針對 QTextStream .
另請參閱 setFieldWidth ().
寫入字符串 string 到流,並返迴引用針對 QTextStream . The string is first encoded using the assigned encoding (the default is UTF-8) before it is written to the stream.
另請參閱 setFieldWidth () 和 setEncoding ().
寫入實數 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 ().
寫入整數數字 i 到流,然後返迴引用針對 QTextStream . By default, the number is stored in decimal form, but you can also set the base by calling setIntegerBase ().
另請參閱 setFieldWidth () 和 setNumberFlags ().
這是重載函數。
寫入 string 到流,並返迴引用針對 QTextStream .
這是重載函數。
寫入 string 到流,並返迴引用針對 QTextStream .
這是重載函數。
轉換 c 從 ASCII 到 QChar ,然後將它寫入流。
[since 6.3.1]
QTextStream
&QTextStream::
operator<<
(
char16_t
c
)
這是重載函數。
寫入 Unicode 字符 c 到流,然後返迴引用針對 QTextStream .
該函數在 Qt 6.3.1 引入。
這是重載函數。
寫入 array 到流。內容對於 array 的轉換是采用 QString::fromUtf8 ().
這是重載函數。
寫入常量字符串指嚮通過 string 到流。 string is assumed to be in UTF-8 encoding. This operator is convenient when working with constant string data. Example:
QTextStream out(stdout); out << "Qt rocks!" << Qt::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 到流以具有基的十六進製數形式。
這是重載函數。
寫入 double f 到流。
這是重載函數。
寫入有符號整數 i 到流。
這是重載函數。
寫入有符號 long i 到流。
這是重載函數。
寫入 qlonglong i 到流。
這是重載函數。
寫入 qulonglong i 到流。
這是重載函數。
寫入無符號整數 i 到流。
這是重載函數。
寫入無符號 long i 到流。
這是重載函數。
寫入無符號短整數 i 到流。
從流讀取字符並把它存儲在 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 跳過。
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
).
跳過前導空白。
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.
跳過前導空白。
讀取整數從流並把它存儲在 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.
跳過前導空白。
這是重載函數。
把單詞轉換成 UTF-8,然後把它存儲在 array .
另請參閱 QString::toLatin1 ().
這是重載函數。
從流讀取字符並把它存儲在 c . The character from the stream is converted to ISO-8859-1 before it is stored.
另請參閱 QChar::toLatin1 ().
這是重載函數。
Converts the word to UTF-8 and stores it 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. For a word consisting of
n
QChars, the buffer needs to be at least
3*n+1
characters long.
若可能的話,使用 QByteArray 操作符代替。
[since 6.4]
QTextStream
&QTextStream::
operator>>
(
char16_t
&
c
)
這是重載函數。
從流讀取字符並把它存儲在 c .
該函數在 Qt 6.4 引入。
這是重載函數。
把實數存儲在 double f .
這是重載函數。
Stores the integer in the signed int i .
這是重載函數。
Stores the integer in the signed long i .
這是重載函數。
Stores the integer in the qlonglong i .
這是重載函數。
Stores the integer in the qulonglong i .
這是重載函數。
Stores the integer in the unsigned int i .
這是重載函數。
Stores the integer in the unsigned long i .
這是重載函數。
Stores the integer in the unsigned short i .
相當於 QTextStream::setFieldWidth ( width ).
相當於 QTextStream::setPadChar ( ch ).
相當於 QTextStream::setRealNumberPrecision ( precision ).