Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views3 pages

Topic 3 - Data Input and Output-1

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

Topic 3 - Data Input and Output-1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1

TOPIC 3. DATA INPUT AND OUTPUT


Header file <iostream.h>
Definition: It provides basic input and output services for C++ programs by using cin and
cout with Insertion and extraction operators. iostream uses the objects cin , cout , cerr , and
clog for sending data to and from the standard streams input, output, error (unbuffered), and
log (buffered) respectively.
Manipulators: Header file <iomanip.h>
Manipulators are helping functions that can modify the input/output stream. It does not
mean that we change the value of a variable, it only modifies the I/O stream using insertion
(<<) and extraction (>>) operators.

Sr. Function Definition


No
1. setw() It is used to set the field width in output operations.
2. endl It is used to enter a new line and after entering a new line it
flushes (i.e. it forces all the output written on the screen or in
the file) the output stream.
3. setprecision() It sets val as the new value for the precision of floating-point
values.
4. setfill() It is used to fill the character ‘c’ on output stream.
5. Setiosflags(flag) It is used to set the format flags specified by parameter mask.
Eg: ios::left
Flags

1. left It adjusts output to the left.

2. right It adjusts output to the right.

3. scientific It uses scientific floating-point notation.

4. fixed It uses decimal notation for floating-point values.

5. showpos It forces to show a positive sign on positive numbers.

6. skipws
This flag skips the whitespaces(spaces, tabs and newlines) in
the input stream before the first non-whitespace character.
7. showpoint It is used to set the showpoint format flag for the specified str
stream. This flag always displays the floating-point values
along with their decimal values.

8. unitbuf When the unitbuf flag is set, the associated buffer is flushed
after each insertion operation

TOPIC 4 – DATA INPUT AND OUTPUT TR. ADITI P. NAIK, DBHSS


2

Use of editor, basic commands of editor, Compilation, Linking and


Execution of Program, Debugging.
Basic commands of editor/compiler: eg. Dev C++ 4.9.9.1
1. Creation of a new file
File-> New/ CTRL +N

2. Saving a file with a filename.cpp


File-> Save As/ CTRL + F12

3. Compile a file
Execute->Compile/ CTRL+ F9

4. Linking and execution of a program


Execute->Run/ CTRL+ F10

5. Debugging
It is process by which the program tries to remove bugs/ errors from the program to
make it behave as expected.

6. Checking the output


Once the program is error free (syntax + logical+ runtime), one can enter the valid
input and check the corresponding valid output. Use function getch() to freeze the
output screen.

EXAMPLE:
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int a=60;
double b=13.0987888, c=12.34,d=5;
cout<<d<<endl;
cout<<a<<setw(10)<<endl;
cout<<setprecision(7)<<b<<endl;
cout<<setfill('*')<<setw(10)<<a<<endl;
cout<<setw(50)<<setiosflags(ios::left)<<"align to left"<<endl;
cout<<setw(50)<<setiosflags(ios::right)<<"align to right"<<endl;
cout<<"with scientific flag"<<scientific<<b<<endl;
cout<<"with fixed flag"<<fixed<<c<<endl;
cout<<showpoint<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl;
cout<<showpos<<a<<"\t"<<b<<endl;
}

TOPIC 4 – DATA INPUT AND OUTPUT TR. ADITI P. NAIK, DBHSS


3

OUTPUT :
5
60
13.09879
********60
align to left*************************************
************************************align to right
with scientific flag1.3098789e+001
with fixed flag12.3400000
60 13.0987888 12.3400000 5.0000000
+60 +13.0987888

--------------------------------

TOPIC 4 – DATA INPUT AND OUTPUT TR. ADITI P. NAIK, DBHSS

You might also like