Home | | Computer Science 11th std | Standard input/output (stdio.h) - C++ Header Files and Built-in Functions

Chapter: 11th Computer Science : Chapter 11 : Functions

Standard input/output (stdio.h) - C++ Header Files and Built-in Functions

This header file defines the standard I/O predefined functions getchar(), putchar(), gets(), puts() and etc.

Standard input/output (stdio.h)

 

This header file defines the standard I/O predefined functions getchar(), putchar(), gets(), puts() and etc.

 

1. getchar() and putchar() functions

 

The predefined function getchar() is used to get a single character from keyboard and putchar() function is used to display it.

 

Program 11.1 C++ code to accept a character and displays it

#include<iostream>

#include<stdio.h>

using namespace std;

int main()

{

      cout<<"\n Type a Character : ";

      char ch = getchar();

      cout << "\n The entered Character is: ";

      putchar(ch);

      return 0;

}

Output:

Type a Character : T

The entered Character is: T

 

2. gets() and puts() functions

 

Function gets() reads a string from standard input and stores it into the string pointed by the variable. Function puts() prints the string read by gets() function in a newline.

 

Program 11.2 C++ code to accepts and display a string

#include<iostream>

#include<stdio.h>

using namespace std;

int main()

{

      char str[50];

      cout<<"Enter a string : ";

      gets(str);

      cout<<"You entered: "

      puts(str);

      return(0);

}

Output :

Enter a string : Computer Science

You entered: Computer Science


Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
11th Computer Science : Chapter 11 : Functions : Standard input/output (stdio.h) - C++ Header Files and Built-in Functions |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.