advertisement

Console Io Operations

60 %
40 %
advertisement
Information about Console Io Operations

Published on January 28, 2009

Author: archikabhatia

Source: slideshare.net

Description

explains some of the character and string input output functions
advertisement

CONSOLE I/O OPERATIONS Console I/O functions perform input from standard input devices and gives output to the standard output device of a system. Generally, keyboard is standard input device And monitor is standard output device

Header files and their purpose Certain functions in C++ are available in C++ header files. Header file is included in the program using a preprocessor directive #include. Preprocessor directive means it is an instruction for the compiler that it is to be carried out in the preprocessing stage. Preprocessing stage means before the actual compilation of the program code.

Certain functions in C++ are available in C++ header files.

Header file is included in the program using a preprocessor directive #include.

Preprocessor directive means it is an instruction for the compiler that it is to be carried out in the preprocessing stage.

Preprocessing stage means before the actual compilation of the program code.

#include directive Instructs the compiler to read and include the header file under the current file. After including the specified file, the compiler compiles the total code ( i.e code of included file as well as current file ).

Instructs the compiler to read and include the header file under the current file.

After including the specified file, the compiler compiles the total code ( i.e code of included file as well as current file ).

SINGLE CHARACTER FUNCTIONS getchar() and putchar() Header file – stdio.h Function is buffered i.e. Character typed by the user is not passed to the variable until the user hits the Enter key. Since Enter key is itself a character and gets stored in the buffer. To clear the input buffer fflush(stdin) function is to be used. Putchar() is used to send single character to the output device. It is also buffered , therefore to clean the output buffer function fflush(stdout) is used.

getchar() and putchar()

Header file – stdio.h

Function is buffered i.e. Character typed by the user is not passed to the variable until the user hits the Enter key.

Since Enter key is itself a character and gets stored in the buffer.

To clear the input buffer fflush(stdin) function is to be used.

Putchar() is used to send single character to the output device.

It is also buffered , therefore to clean the output buffer function fflush(stdout) is used.

Example: Program using getchar() and putchar() function. Program to accept characters from the user till ‘n’ or ‘N’ is pressed. void main() { do { char ch; ch = getchar ( ); fflush(stdin); putchar(ch); fflush(stdout); } while((ch!=‘n’)&&(ch!=‘N’)); }

void main()

{

do

{

char ch;

ch = getchar ( );

fflush(stdin);

putchar(ch);

fflush(stdout);

} while((ch!=‘n’)&&(ch!=‘N’));

}

getc() and putc( ) functions Header file: stdio.h Mainly used with files getc( stdin ) : Same as getchar( ) except that getchar( ) reads a character from the keyboard by default whereas stdin of function getc(stdin) make it read from a file represented by a standard input device. putc(ch, stdout) : sends the character stored in ‘ch’ variable to standard output device.

Header file: stdio.h

Mainly used with files

getc( stdin ) : Same as getchar( ) except that getchar( ) reads a character from the keyboard by default whereas stdin of function getc(stdin) make it read from a file represented by a standard input device.

putc(ch, stdout) : sends the character stored in ‘ch’ variable to standard output device.

getche( ) and putch( ) Header file: conio.h This function does not wait fro the enter key to be pressed Displays the input character ch e stands for echo Different from getch( ) function since getch() does not display the input character.

Header file: conio.h

This function does not wait fro the enter key to be pressed

Displays the input character ch

e stands for echo

Different from getch( ) function since getch() does not display the input character.

The classes istream (input stream ) and ostream (output stream) defined under iostream.h define some functions to handle character and string input/output operations. get( ) When >> operator is used with cin, it cannot accept spaces and newline characters. When cin.get(ch) is used, it reads spaces and newline character as well. put( ) cout.put(ch)

get( )

When >> operator is used with cin, it cannot accept spaces and newline characters.

When cin.get(ch) is used, it reads spaces and newline character as well.

put( )

cout.put(ch)

STRING BASED FUNCTIONS gets( ) and puts( ) Header file – stdio.h Reads a string from standard input device Also buffered , therefore need to press enter key Therefore, fflush needs to be used to clear IP buffer Can accept spaces Different from cin function because cin cannot accept spaces.

gets( ) and puts( )

Header file – stdio.h

Reads a string from standard input device

Also buffered , therefore need to press enter key

Therefore, fflush needs to be used to clear IP buffer

Can accept spaces

Different from cin function because cin cannot accept spaces.

getline( ) function Reads a line of text Syntax: cin.getline( var name, size) Size is the total no. of characters including one null character : ‘’

Reads a line of text

Syntax: cin.getline( var name, size)

Size is the total no. of characters including one null character : ‘’

Add a comment

Related pages

Console (Java Platform SE 7 ) - Oracle Help Center

java.io.Console; All Implemented Interfaces: ... The bulk read operations read ... IOError - If an I/O error occurs.
Read more

C# Questions & Answers - Introduction of Console I/O ...

This section of our 1000+ C# multiple choice questions focuses on input and output operations on console in C# Programming Language. 1. Which of the ...
Read more

Basic Input/Output - C++ Tutorials - cplusplus.com - The ...

Basic Input/Output The example programs ... // i/o example #include ... The standard behavior that most users expect from a console program is that each ...
Read more

Console IO Operations in C Language - C Training - YouTube

Best C Training is the right choice to train here in depth course of C Language, the video is prepared by Mr.Sandeep Soni, who has 17+ years exp ...
Read more

C# Tutorials + Programming: Managing Console I/O Operations

Managing Console I/O Operations Console input/ouput operations are carried out by the Console class which is inside system namespace and is stored in ...
Read more

C# - File I/O - Tutorials for SAP Lumira, PHP7, Python3 ...

C# - File I/O - Learn C Sharp Programming in simple and easy steps starting from Environment setup, Basic Syntax, Data Types, Type Conversion, Variables ...
Read more

C++ Programming Language - C++ IO Streams and File Input ...

C++ Programming Language Stream IO and File IO. ... If IO operations are not defined ... the stream object to an actual IO device (e.g., keyboard, console ...
Read more

Lesson: Basic I/O (The Java™ Tutorials > Essential Classes)

Lesson: Basic I/O. This lesson covers ... I/O from the Command Line describes the Standard Streams and the Console object. ... Some I/O operations are ...
Read more

How to measure Operations Manager database performance ...

How to measure Operations Manager database performance. ... and the Operations Console has been delivered to your ... Predeployment I/O Best ...
Read more