100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.6 TrustPilot
logo-home
Summary

Summary C++ BASIC INPUT-OUTPUT

Rating
-
Sold
-
Pages
5
Uploaded on
25-07-2024
Written in
2023/2024

The document provides an overview of basic input-output in C++, essential for interactive programming. It covers standard input (cin) and output (cout) streams, along with common operations like reading from the keyboard and displaying text on the screen. Detailed explanations of formatted and unformatted I/O are included, with practical examples demonstrating their usage. The notes also discuss error handling and stream manipulation, highlighting best practices to ensure efficient and user-friendly input-output operations in C++.

Show more Read less









Whoops! We can’t load your doc right now. Try again or contact support.

Document information

Uploaded on
July 25, 2024
Number of pages
5
Written in
2023/2024
Type
Summary

Content preview

ELITE TUTORING




C++ Basic Input/Output
In this topic, we will learn to use the cin object to take input from the user, and
the cout object to display output to the user with the help of examples.

C++ Output
In C++, cout sends formatted output to standard output devices, such as the
screen. We use the cout object along with the << operator for displaying output.




Example 1: String Output
#include <iostream>
using namespace std;

int main() {
// prints the string enclosed in double quotes
cout << "This is C++ Programming";
return 0;
}

Output

This is C++ Programming


How does this program work?
• We first include the iostream header file that allows us to display output.
• The cout object is defined inside the std namespace. To use
the std namespace, we used the using namespace std; statement.
• Every C++ program starts with the main() function. The code execution
begins from the start of the main() function.

, ELITE TUTORING



• cout is an object that prints the string inside quotation marks " ". It is
followed by the << operator.
• return 0; is the "exit status" of the main() function. The program ends with
this statement, however, this statement is not mandatory.
Note: If we don't include the using namespace std; statement, we need to
use std::cout instead of cout .

This is the preferred method as using the std namespace can create potential
problems.
However, we have used the std namespace in order to make the codes more
readable.
#include <iostream>

int main() {
// prints the string enclosed in double quotes
std::cout << "This is C++ Programming";
return 0;
}




Example 2: Numbers and Characters Output

To print the numbers and character variables, we use the same cout object but
without using quotation marks.
#include <iostream>
using namespace std;

int main() {
int num1 = 70;
double num2 = 256.783;
char ch = 'A';

cout << num1 << endl; // print integer
$5.99
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
peterkuria3

Also available in package deal

Thumbnail
Package deal
C Programming Language
-
8 2024
$ 48.22 More info

Get to know the seller

Seller avatar
peterkuria3 Harvard University
View profile
Follow You need to be logged in order to follow users or courses
Sold
0
Member since
1 year
Number of followers
1
Documents
69
Last sold
-
ELITE TUTORING

Elite Tutoring is your ultimate destination for academic success. I offer a curated selection of high-quality study tools designed to enhance your learning experience and boost exam performance. From comprehensive study guides and interactive practice exams to expert-recommended resources, I provide everything you need to excel. Trust Elite Tutoring to turn your academic challenges into triumphs and help you pass your exams with confidence.

Read more Read less
0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions