Following area the input functions/statement in C++.
gets() STATEMENT
cin STATEMENT
cin stands for “Character Input”. In C++, cin reads formatted data as input from keyboard.cin
object is used along with the extraction operator (>>) to accept data from standard input device.
Syntax
cin >> variable;
Example:
#include<iostream>
using namespace std;
int main()
{
int b;
cin >>b; // cin takes input in “b” variable
return 0;
}
getchar() STATEMENT:
The getchar() function reads the available character from the keyboard. This function reads
only single character at a time. When the user presses the key, getchar() requires Enter key
to be pressed. This function is defined in <stdio.h> header file.
example
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
char b;
cout<<“\n Enter a character:”;ot.com
b = getchar();
cout<<“\n Input character is ” << b;
return 0;
getch() STATEMENT
The getch() function reads the character from the keyboard. This function reads only
single character and not printed on the screen. This function takes input and does not
requires Enter key to be pressed. This function is defined in <conio.h> header file.
example
char ch;
cout<<“\n Enter a character:”;
ch = getch();
cout<<“\n Input character is ” << ch;
return 0;
char name [25];
cout<<“\n Enter your name:”;
gets(name);
cout<<“\n Your Name is ” << name;
return 0;
using namespace std;
getche() STATEMENT:
The getche() function reads the character from the keyboard and echoes on the screen. It
reads only single character and displays on the screen. This function takes input and does
not require Enter key to be pressed. This function is defined in <conio.h> header file.
example
#include<iostream>
#include<conio.h>
using namespace std;
int main()
char ch;
cout<<“\n Enter a character:”;
ch = getche();
Fot.com
cout<<“\n Input character is ” << ch;
return 0;
}
gets() STATEMENT:
example in C++.
This function is used to reads characters or the string input and stores them until a newline
character found. This function is defined in <cstdio.h> header file.
syntax
example
STATEMENT TERMINATOR (:):
In C++, statement terminator is used to end the statement. Statements are terminated with
semicolon ( 😉 symbol. Every statement in C++ must be terminated otherwise and error
message will occur.
ESCAPE SEQUENCES:
Escape sequences are used to control the cursor moves on screen by using special codes.
An escape sequence is a special non-printing characters consists of the escape character
(the backslash “\”) and a second (code) character. The list of the escape sequences is given
below:
Escapedamjeecoaching.blogspot.com
Sequence
\n
\t\
Explanation with Example
Newline. Position the cursor at the beginning of the next line.
Example: cout << “\n”;
= 10
\a
Horizontal tab. It move the cursor the next tab stop.
Example: cout << “\t”; “
Backslash. Insert a backslash character in a string.
Example: cout << “\\”;
Alert. Produces a beep sound or visible alert.
Example: cout << “\a”;
Backspace. It moves the cursor backspace.
Example: cout << “\b”;
Carriage Return. Moves the cursor to the beginning of the current line.
Example: cout < “\r”;
Single Quotation. It is used to print apostrophe sign (‘).
Example: cout << “\”;
Double Quotation.” It is used to print quotation mark (‘).
Example: cout << “\””;
Remainder Or Modulas: Find remainder after integer
division.
Division; It is used to perform division.
Multiplication: It is used to perform multiplication.
to perform addition.
Subtraction: It is used to perform subtraction.
0 of 8 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 8 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
Which statement correctly describes the purpose of cin in C++?
What is the function of getchar() in C++?
What does the getch() function do in C++?
What is the purpose of gets() function in C++?
Which statement correctly describes getche() function in C++?
In C++, what is the role of the statement terminator (;)?
Which escape sequence is used to produce a beep sound or visible alert?
What is the purpose of the backslash character () in C++?