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 ...
Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.