Lesson2 Basic Input Output in C
Lesson2 Basic Input Output in C
UNIVERSITY
Cabambangan, Villa de Bacolor 2001, Pampanga,
BASIC INPUT/OUTPUT
IN C++
Description
C++ uses a convenient abstraction called streams to perform input and
output operations in sequential media such as the screen, the keyboard or a
file. A stream is an entity where a program can either insert or extract
characters to/from. There is no need to know details about the media
associated to the stream or any of its internal specifications. All we need to
know is that streams are a source/destination of characters, and that these
characters are provided/accepted sequentially (i.e., one after another).
Objectives
After completing the module, the students are expected to:
Understand the input/output functions of C++ programming language
Familiarize with the terms used in C++ programming language
Able to construct the basic structure of C++
Able to write codes using C++ programming language in
Dev C++ IDE Instructions
The standard library defines a handful of stream objects that can be used to access
what are considered the standard sources and destinations of characters by the
environment where the program runs:
STREA DESCRIPTION
M
cin Standard input stream
cout Standard output stream
cerr Standard error (output)
stream
clog Standard logging (output)
stream
The << operator inserts the data that follows it into the stream that precedes it. In the
examples above, it inserted the literal string Output sentence, the number 120, and the
value of variable x into the standard output stream cout. Notice that the sentence in the
first statement is enclosed in double quotes (")
DON HONORIO VENTURA STATE
UNIVERSITY
Cabambangan, Villa de Bacolor 2001, Pampanga,
because it is a string literal, while in the last one, x is not. The double quoting is what
makes the difference; when the text is enclosed between them, the text is printed literally;
when they are not, the text is interpreted as the identifier of a variable, and its value is
printed instead. For example, these two sentences have very different results:
For formatted input operations, cin is used together with the extraction operator, which is written as >>
(i.e., two "greater than" signs). This operator is then followed by the variable where the extracted data is stored.
DON HONORIO VENTURA STATE
UNIVERSITY
Cabambangan, Villa de Bacolor 2001, Pampanga,
References:
Goodrich, Michael et.al (2011). Data Structures and Algorithms in C++. John Wiley & Sons Inc,
United States of America
Educational Technology Journals. http://www.educational-software-directory.net/publications/journals
CPlusPlusNotesForProfessionals. http://www.GoalKicker.com
C++ Tutorials. http://www.programiz.com
C++ Tutorials. http://www.w3schools.in