O'Reilly logo

Object Oriented Programming with C++, Second Edition by Sunil Patekar, Mahesh Bhave

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

APPENDIX G: SIMPLE C STYLE INPUT–OUTPUT

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.

G.1 I/O OF CHARACTER

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.

Program G.1 Using getchar() & putchar()

//  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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required