1 Simple Input/Output  C++ offers the iostream library, which defines a system of character-oriented Input/Output (I/O) using object oriented programming.

Slides:



Advertisements
Similar presentations
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Advertisements

Chapter 3. Expressions and Interactivity CSC125 Introduction to C++
Computer Programming Basics Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University, Korea.
CS-1030 Dr. Mark L. Hornick 1 IOStreams revisited Streams, strings, and files.
I/O and Program Control Statements Dick Steflik. Overloading C++ provides two types of overloading –function overloading the ability to use the same function.
Input/Output Main Memory istream ostream Disk Drive Keyboard Scanner Disk Drive Monitor Printer stream = sequence of bytes.
1 Lecture 5: Input/Output (I) Introduction to Computer Science Spring 2006.
How to Program in C++ CHAPTER 3: INPUT & OUTPUT INSTRUCTOR: MOHAMMAD MOJADDAM.
Chapter 3: Input/Output
Programming is instructing a computer to perform a task for you with the help of a programming language.
Input/Output in C++ C++ iostream.h instead of stdio.h Why change? –Input/output routines in iostream can be extended to new types declared by the user.
Input and Output in Console Mode UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) ADNAN BABAR MT14028 CR
CSCI 1730 January 17 th, 2012 © by Pearson Education, Inc. All Rights Reserved.
CSIS 123A Lecture 5 Friend Functions Glenn Stevenson CSIS 113A MSJC.
DCS 5085 C++ Fundamentals Chapter 4. Overview Basics of a typical C++ Environment C++ Stream Input/Output Classic Stream vs. Standard Stream Iostream.
Ch 10. Input/Output1 Ch. 10 Input/Output Oregon State University Timothy Budd.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
C++ Streams Lecture-2.
C++ Lecture 8 Monday, 25 August I/O, File, and Preprocessing l An in-depth review of stream input/output l File handling in C++ l C++ preprocessing.
Chapter 10C++ for Java Programmers1 Chapter 10 Input/Output.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 3: Input/Output.
THE BASICS OF A C++ PROGRAM EDP 4 / MATH 23 TTH 5:45 – 7:15.
C++ Streams Lecture-2. C++ Streams Stream  A transfer of information in the form of a sequence of bytes I/O Operations:  Input stream: A stream that.
Input/Output Sujana Jyothi C++ Workshop Day 2. C++ I/O Basics 2 I/O - Input/Output is one of the first aspects of programming that needs to be mastered:
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
Control Structures (B) Topics to cover here: Sequencing in C++ language.
Lecture Contents I/O Streams. –Input/output streams. –Unformatted vs formatted streams. –Stream manipulators. –Stream error state. –Stream tying. –Examples.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 21 - C++ Stream Input/Output Basics Outline 21.1Introduction 21.2Streams Iostream Library.
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester 1436 King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah Alakeel.
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah.
Chapter 3: Input/Output
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
C++ REVIEW INPUT/OUTPUT (I/O). BRIEF NOTE “CLASSES” AND “STRUCTS” AND “TYPES” They are ADTs… They define data and operations on that data The ADTs in.
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah.
Chapter 3: Input/Output. Objectives In this chapter, you will: – Learn what a stream is and examine input and output streams – Explore how to read data.
1 COMS 261 Computer Science I Title: Functions Date: October 24, 2005 Lecture Number: 22.
Input/Output. Objectives In this chapter you will: Learn what a stream is and examine input and output streams Explore how to use the input stream functions.
File Processing Files are used for data persistance-permanent retention of large amounts of data. Computer store files on secondary storage devices,such.
Input/Output in C++ C++ iostream.h instead of stdio.h Why change? –Input/output routines in iostream can be extended to new types declared by the user.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
CS116 SENEM KUMOVA METİN. Outline What is C++ ? Some features of C++ Input and Output Operations Manipulators C++ header files Namespaces and scope resolution.
CCSA 221 Programming in C INPUT AND OUTPUT OPERATIONS IN C – PART 1 1.
CSE 232: Moving Data Within a C++ Program Moving Data Within a C++ Program Input –Getting data from the command line (we’ve looked at this) –Getting data.
Prepared by Andrew Jung. Contents A Simple program – C++ C++ Standard Library & Header files Inline Functions References and Reference Parameters Empty.
Chapter 3: Input/Output. Objectives In this chapter, you will: – Learn what a stream is and examine input and output streams – Explore how to read data.
INPUT & OUTPUT 10/20/2016Department of Computer Science, UOM | Introduction | Fakhre Alam.
Introduction Every program takes some data as input and generate processed data as out put . It is important to know how to provide the input data and.
CS212: Object Oriented Analysis and Design
Introduction to C++ (Extensions to C)
C++ Basic Input and Output (I/O)
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
Standard Input - Output
Register Use Policy Conventions
Chapter 2 part #3 C++ Input / Output
IO Overview CSCE 121 J. Michael Moore
Manipulators CSCE 121 J. Michael Moore
Programming Funamental slides
Chapter 3: Input/Output
Pass by Reference.
Programs written in C and C++ can run on many different computers
Chapter 2 part #3 C++ Input / Output
ENERGY 211 / CME 211 Lecture 9 October 10, 2008.
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Chapter 1 c++ structure C++ Input / Output
IO Overview CSCE 121 Strongly influenced by slides created by Bjarne Stroustrup and Jennifer Welch.
Input/Output Streams, Part 1
Introduction to Programming
Presentation transcript:

1 Simple Input/Output  C++ offers the iostream library, which defines a system of character-oriented Input/Output (I/O) using object oriented programming.

2 Simple Input/Output When a C++ program that includes the iostream classes starts, four objects are created and initialized:  cin handles input from the standard input, the keyboard.  cout handles output to the standard output, the screen.  cerr handles unbuffered output to the standard error device, the screen.  clog handles buffered error messages that are output to the standard error device, the screen.

3 Simple Input/Output  Printing output  To send data to standard output, use the operator <<. For example: cout << "cout example !"; sends the string “cout example” to the object called cout.

4 Simple Input/Output  The operator << is overloaded with a variety of meanings when used with cout, so you can print on the screen different arguments:  Characters  Strings  Integers  Floating-point numbers  Addresses

Simple Input/Output  Example of printing on screen with << operator #include int main (void) { cout << "It will be printed different type of data:\n"; cout << "string: " << "abcd" <<endl; cout << "char: " << 'a' << endl; cout << "char: " << char(97) <<endl; cout << "non-printing char (escape): "<< char(27) << endl; cout << "integer: " << 123 <<endl; cout << "long: " << <<endl; cout << "double: " << << endl; cout << “\n\n " ; cout << "Here is a very big number:\t" << << endl; cout << "Here is the sum of 8 and 5:\t" << 8+5 << endl; cout << "Here's a fraction:\t\t" << (float) 5/8 << endl; cout << "And a very very big number:\t" << (double) 7000 * 7000 << endl; }

6 Simple Input/Output  Reading input  To read data from standard input, use the operator >>. For example: int a; cin >> a; This operator waits for the same kind of input as its argument (in our example int).

7 Simple Input/Output  Both > enable multiple input or multiple output operations and permit using of manipulators to change the format of I/O data #include int main (void) { // Specifying formats with manipulators: int integer; cout << "input a number in decimal: " ; cin >> integer; cout << "in octal is: " << oct << integer << endl; cout << "in hex is: " << hex << integer << endl; cout << "input a number in octal: " ; cin >> oct >> integer; cout << "in decimal is: " << dec << integer << endl; cout << "in hex is: " << hex << integer << endl; }