0% found this document useful (0 votes)
16 views

Input Output

Uploaded by

Rahul 4sure
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
16 views

Input Output

Uploaded by

Rahul 4sure
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 7
4.1 C++STREAMS C++ provides a new technique for handling I/O operations through a mechanism known as_streams, ‘ream is an_abstraction that refers to the flow of data. The flow of data may be from an input device (keyboard, dis ile etc.) to.a program in main. memory of-from a progras to any-output device (monitor, printer etc.) —.. a 4 Stréamis can be classified into two categories : gOutput Stream : eTnput Si vutput stream, the flow of data (bytes) is from the program to the output device. Output operations are carried out_using output sweat CFF. Inaput stream, the flow of data is from the input device to the program in main memory. In C+, input operations are carried out using input stream: * 43 INPUTUSING cin ‘The cin is used to input a number, a character or a string of characters from a standaj input device i.e. keyboard. ——— The standard input stream in C++ is represented using pre-defined object ‘cin ( pronounced as see-in) so as to perform standard input operations. The cin stream is used in conjunction_with bitwise right shif shift ft operator >) for performing standard input operations. The syntax for the standard input stream opera ii Predefined object Extrac ‘or get from operator IC L. cin ‘>> var: le ; e ; //Data flow in the direction of arrow Om ere variable cant be of any basic or user defined data type. In the cin statement, cin is wi rowed by the extraction or get from operator (>>) and then followed with variable into which jnput data is to be stored. The operator (>>) is called extraction or get from operator as it we Tas the data from standard input stream ein connected to standard input device (keyboard) et eends the data into the variable that follows it. ‘te whole process of inputting using cin is shown below : T Variable , HE-©) Keyboard (___ Cc Fig. 4.3 - Input using cin Now, consider the following statements, \se ‘oO et int x; . cin>>x; ‘This input statement accepts an integer value from keyboard and stores in the variable x 4.2 OUTPUT USING cout The-cout is used to display a variable, constant or expression onto the standard outpt device ie. monitor. —— oe In C++, the standard output stream is represented _using pre-defined object cout (Pronounced as see-out), so as to perform standard output operation. The cout stream is used in’| Conjunction with bitwise left shift operator (<<) for performing standard output operations. The syntax for the standard output stream operation is predefined object "Insertion or Put to operator esd | Date fl Ga ens ce ore where data can be a variable, expression, user-defined datatypes or a constant. In th cout statement, oUt is ‘followed by the-insertion or put t operator (<<) and then fi ith data items which are to be displayed. he operator (<<) is called the insertion or put to operator as it inserts the data that follows it into the cout stream whicl further directs the contents to the ese Ne ead te display_screen- The whole process of outputing using cout corresponding to statement cout<<"KING” ; js shown below data Now, consider the following statement, cout<<"Hello Everybody”; Monitor Fig 4.2 - Output using cout The insertion operator (<<) can be used more then once in a same cout statement. Such output operations are called chaining or cascaded output operations. The main advantage of repeating the insertion operator is to display a combination of variables, constants and expressions in the same statement. Consider the example, (avads4 ’ “= “< : Fru quam to eobeul #include Nos: int a,b,c,sum; : ‘ cout<<"Enter three numbers = cin>>a>>b>>c; “sum=atbtc; z cout<<"Sum = "<

You might also like