0% found this document useful (0 votes)
2 views11 pages

CPP 4

The document discusses Input/Output (I/O) functions in C++, explaining how programs communicate with users through input and output. It covers standard output functions using the iostream library, the cout object, escape sequences for formatting, and various input methods like cin and getline. Additionally, it differentiates between console input/output functions and specific character reading functions such as getch(), getche(), and getchar().

Uploaded by

outlooksinet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views11 pages

CPP 4

The document discusses Input/Output (I/O) functions in C++, explaining how programs communicate with users through input and output. It covers standard output functions using the iostream library, the cout object, escape sequences for formatting, and various input methods like cin and getline. Additionally, it differentiates between console input/output functions and specific character reading functions such as getch(), getche(), and getchar().

Uploaded by

outlooksinet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Input/Output Functions

SESSION 4
Input/Output
Input/Output (I/O) is how programs

communicate with users.


Input: Data given by user → Program

Output: Data shown by program → User

In C++, I/O can be done using:


iostream (C++ way)

stdio.h (C-style I/O functions)


Standard Output Functions
Header file: #include <iostream>

Uses streams for input and output.

Important objects:
cout → Standard Output Stream

cin → Standard Input Stream

Part of the std namespace → Use std::cout, or

using namespace std;


The cout Object and << Operator
Syntax: cout << "Hello";

<< is the insertion operator (puts data into

output stream).
Can chain multiple outputs:

cout << "Name: " << name << ", Age: " <<
age;
Data is sent to the console in sequence.
Escape Sequences
Escape sequences start with \ and allow special
formatting:

Sequence Description

\n New Line

\t Horizontal Tab

\\ Backslash

\" Double Quote

\a Alert (Beep sound)


🔹 \n – New Line
.
Moves the cursor to the next line.
Eg: "Hello\nWorld!“
🔹 \t – Horizontal Tab
Inserts a tab space (like pressing Tab key).
Eg: "Name\t:\tJohn\nAge\t:\t20“
🔹 \\ – Backslash
Prints a single backslash (\).
Eg: "This is a backslash: \\“
🔹 \" – Double Quote
Prints a double quote character.
Eg: "He said, \"C++ is powerful!\""
Console Input/Output Functions
 #include <iostream>: Enables input/output

➡ cin takes input from the user


➡ >> is the extraction operator
➡ cout prints to console
➡ << is the insertion operator
getch(), getche(), getchar()
getch() is read a single character from console

defined in conio.h.
getch() not echo the character.

getche() is read a single character from console

define in conio.h.
getche() echo the character.

getchar() is read a single character from

console defined in stdio.h.


cin vs getline

Feature cin getline(cin, var)

Reads until Whitespace Newline

Works with Any datatype Only string

Useful for Numbers, words Full sentences


Output statement Input Statement
.
‘cout’ is console ‘cin’ is console
output ,used to print input,used to read from
output. console.
cout is the object of cin is the object of
ostream class istream class.

The cout is used in The cin is used in


conjunction with stream conjunction with stream
insertion operator (<<) extraction operator (>>)
to display the output on to read the input from a
a console console.
END

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy