You are on page 1of 2

Whati

saSt
ream?

Astr
eam isanobj
ectwhereaprogram canei
theri
nsertorext
ract
char
acter
stoorfr
om i
t.Thestandardi
nputandoutputstr
eam obj
ect
sof
C++aredecl
aredi
ntheheaderfiei
l ost
ream.

St
andar
dInputSt
ream (i
str
eam )

General
ly,
thedeviceusedf ori
nputi
sthekey board.Forinputti
ng,t
he
keywordcinisused,whichisanobject
.Theov erloadedoperatorof
extr
acti
on,>>,i
susedont hest
andardinputstr
eam, i
nthiscase:ci
n
str
eam.Sy nt
axforusingt hest
andardi
nputst r
eam iscinf ol
lowedbythe
operat
or>>foll
owedbyt hevar
i et
abl hatstoresthedat aextr
actedfrom
thestr
eam.

i
stream obj
ect
sarestream objectsusedtoreadandinter
pretinputf
rom
sequencesofchar
acters.Specif
icmember sareprov
idedtoper f
orm
thesei
nputoperat
ions,whichcanbedi vi
dedintwomai ngroups:

 Formattedi nput
Thesef unctionsextractdataf r
om asequenceofchar act
ersthat
maybei nterpret
edandf ormat tedtoav alueofacer tainty
pe.These
typeofoper ationisperformedusi ngmemberandgl obalfuncti
ons
thatoverloadt heextract
ionoper ator(
).
 Unformat tedinput
Mostoft heothermemberf unct i
onsoft heistr
eam classar eused
toperform unf ormat
t edinput,i
.e.nointerpr
etationi
smadeont he
charactersgotf ormt heinput.Thesememberf unct
ionscangeta
determinednumberofchar actersfrom theinputcharacter
sequence

Thest
andar
dobj
ectci
nisani
nst
ant
iat
ionoft
hiscl
ass.

St
andar
dOut
putSt
ream (ost
ream )

Bydef aul
t,t
hedev i
ceusedforoutputi
st hescr
eenoft hecomput er.For
outputti
ngvaluesthekeywordcoutisused,whichisanobject.The
i
nser t
ionoperator<<i
susedont hestandardoutputcoutstr
eam.  The
syntaxforusingthestandar
doutputstr
eam iscoutfoll
owedbyt he
operator<<foll
owedbyt heval
uetobei nser
tedoroutputbytheinser t
ion
oper
ator
.

ostream obj
ectsarestream obj
ectsusedt
owrit
eandformatoutputas
sequencesofchar act
ers.Speci
fi
cmember sar
eprov
idedtoperf
orm
theseoutputoperati
ons,whichcanbedivi
dedi
ntwomai ngr
oups:

 Formattedoutput
Thesememberf uncti
onsint er
pretandf ormatt hedat atobewr it
ten
assequencesofchar acters.Theset y peofoper at
ionisperformed
usingmemberandgl obalfunctionst hatov erloadtheinserti
on
operat
or
 Unformattedout put
Mostoft heothermemberf unctionsoft heost r
eam classareused
toperform unformat t
edout putoper ations, i
.e.outputoperati
ons
thatwrit
et hedataasi tis,
wi thnof ormat t
ingadapt ati
ons.These
memberf unct
ionscanwr i
teadet er
mi nednumberofchar actersto
theoutputchar actersequence( put,wr ite)

Thest
andar
dobj
ect
scouti
sinst
ant
iat
ionsoft
hiscl
ass.

i
ostr
eam object
sinher
ital
lmembersfr
om bothistr
eam andost
ream,
thus
bei
ngabl
et operfor
m bothi
nputandoutputoper
ati
ons.

You might also like