May 2012
Intermediate to advanced
679 pages
16h 56m
English
As C++ is a superset of C, it supports all the facilities of I/O in C. Let us have a brief look at the same.
As basic data element is character, C offers functions for reading and writing characters. They are putchar() and getchar() .
Let us study a simple program.
Problem: Write a program to study functions getchar() and putchar().
Solution: See Program G.1.
// io3.cpp#include<stdio.h>int main(){ char ch1,ch2; ch1 = getchar(); putchar(ch1); ch2 = getchar(); putchar(ch2); return 0;}
If you run this program and type ABCD and press return then you will get the output as shown below:
OUTPUT ABCD AB
If you run this program, and type ...
Read now
Unlock full access