Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
src_corelib_io_qtextstream.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4
#
include
<
QFile
>
5
#
include
<
QTextStream
>
6
7
void
wrap_func
()
8
{
9
{
10
//! [0]
11
QFile data(
"output.txt"
);
12
if
(data.open(QFile::WriteOnly | QFile::Truncate)) {
13
QTextStream out(&data);
14
out <<
"Result: "
<< qSetFieldWidth(10) << Qt::left << 3.14 << 2.7;
15
// writes "Result: 3.14 2.7 "
16
}
17
//! [0]
18
}
19
20
{
21
//! [1]
22
QTextStream stream(stdin);
23
QString line;
24
while
(stream.readLineInto(&line)) {
25
//...
26
}
27
//! [1]
28
}
29
30
{
31
//! [2]
32
QTextStream in(
"0x50 0x20"
);
33
int
firstNumber, secondNumber;
34
35
in >> firstNumber;
// firstNumber == 80
36
in >> Qt::dec >> secondNumber;
// secondNumber == 0
37
38
char
ch;
39
in >> ch;
// ch == 'x'
40
//! [2]
41
}
42
}
43
44
//! [3]
45
int
main
(
int
argc,
char
*argv[])
46
{
47
// read numeric arguments (123, 0x20, 4.5...)
48
for
(
int
i = 1; i < argc; ++i) {
49
int
number;
50
QTextStream in(argv[i]);
51
in >> number;
52
//...
53
}
54
}
55
//! [3]
56
57
58
void
examples
()
59
{
60
{
61
//! [4]
62
QString str;
63
QTextStream in(stdin);
64
in >> str;
65
//! [4]
66
}
67
68
{
69
//! [5]
70
QString s;
71
QTextStream out(&s);
72
out.setFieldWidth(10);
73
out.setFieldAlignment(QTextStream::AlignCenter);
74
out.setPadChar(
'-'
);
75
out <<
"Qt"
<<
"rocks!"
;
76
//! [5]
77
}
78
79
#
if
0
80
//! [6]
81
----Qt------rocks!--
82
//! [6]
83
#
endif
84
85
{
86
QString *file;
87
//! [7]
88
QTextStream in(file);
89
QChar ch1, ch2, ch3;
90
in >> ch1 >> ch2 >> ch3;
91
//! [7]
92
}
93
94
{
95
//! [8]
96
QTextStream out(stdout);
97
out <<
"Qt rocks!"
<< Qt::endl;
98
//! [8]
99
}
100
101
{
102
QTextStream stream;
103
//! [9]
104
stream <<
'\n'
<< Qt::flush;
105
//! [9]
106
}
107
}
main
int main(int argc, char *argv[])
[ctor_close]
Definition
src_corelib_animation_qpropertyanimation.cpp:100
examples
bool examples()
[3]
Definition
src_corelib_global_qglobal.cpp:56
wrap_func
void wrap_func()
Definition
src_corelib_io_qtextstream.cpp:7
qtbase
src
corelib
doc
snippets
code
src_corelib_io_qtextstream.cpp
Generated on
for Qt by
1.18.0