Programming Stream Manipulators. COMP102 Prog. Fundamentals I: Stream Manipulator Slide 2 Stream Manipulators in iostream.h Library I/O stream manipulators.

Slides:



Advertisements
Similar presentations
Chapter 3. Expressions and Interactivity CSC125 Introduction to C++
Advertisements

CS-1030 Dr. Mark L. Hornick 1 IOStreams revisited Streams, strings, and files.
I/O Streams as an Introduction to Objects and Classes
CS1061 C Programming Lecture 16: Formatted I/0 A. O’Riordan, 2004.
I/O and Program Control Statements Dick Steflik. Overloading C++ provides two types of overloading –function overloading the ability to use the same function.
1 CIS Jan Overview Selection Statements –If Statement –Else –Nested If-Else –Switch Repetition Statements –While statement –For Statement.
1 Lecture 6: Input/Output (II) Introduction to Computer Science Spring 2006.
Input/Output Main Memory istream ostream Disk Drive Keyboard Scanner Disk Drive Monitor Printer stream = sequence of bytes.
計算機概論實習 Integral Stream Base expression: dec, oct, hex, setbase, and showbase Use header Integers normally base 10 (decimal) Stream manipulators.
Simplest program and Data Output Sen Zhang. The simplest program looks like a single person company! void main() { // this starts a comment line // here.
Chapter 9 Formatted Input/Output Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
C++ Numerical Data Input/Output Programming. COMP 102 Prog Fundamentals I:C++ Numerical Data, Input/Output /Slide 2 Rules for Division l C++ treats integers.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 11 Chapter 21 - C++ Stream Input/Output Outline 21.1Introduction.
CSE202: Lecture 8The Ohio State University1 Formatting Numbers for Output.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 21 - C++ Stream Input/Output Outline 21.1Introduction 21.2Streams Iostream Library Header.
Unformatted and Formatted I/O Operations. 2 Unformatted Input/output is the most basic form of input/output. Unformatted I/O transfers the internal binary.
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
FORMATTED INPUT OUTPUT. Topics to be discussed……………….. Formatted Console I/O operationsFormatted Console I/O operations Defining field width :Width()Defining.
CHAPTER 7 DATA HANDALING Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 6: Continuing with output formatting.
Chapter 3 COMPLETING THE BASICS Programming Fundamentals with C++1.
CSE1222: Lecture 9The Ohio State University1. Formatting Numbers for Output  Number formatters are to be used in conjunction with cout  For example,
Output Formatting. Precision #include... float grade = f; cout.precision(4); cout
You gotta be cool. Stream Stream Output Stream Input Unformatted I/O with read, gcount and write Stream Manipulators Stream Format States Stream Error.
Bit Manipulation when every bit counts. Questions on Bit Manipulation l what is the motivation for bit manipulation l what is the binary, hexadecimal,
Definition Various stream manipulators can be used to specify the kinds of formatting to be performed during stream-I/O operations. Stream manipulators.
C++ Streams Lecture-2.
Output Formatting No, I don't want 6 digits…. Standard Behavior Rules for printing decimals: – No decimal point: prints as 1 – No trailing zeros:
Chapter 2 Data types, declarations, and displays.
I/O and Data Formatting Introduction to Class Concepts INFSY 307 Spring 2003 Lecture 3.
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:
Fundamental File Processing Operations C++
CPS120: Introduction to Computer Science Formatted I/O.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 11- C++ Stream Input/Output Outline 11.1Introduction 11.2Streams Iostream Library Header.
1 Simple Input/Output  C++ offers the iostream library, which defines a system of character-oriented Input/Output (I/O) using object oriented programming.
Lecture Contents I/O Streams. –Input/output streams. –Unformatted vs formatted streams. –Stream manipulators. –Stream error state. –Stream tying. –Examples.
Student Book Input / Output in C++
COMP102 Lab 071 COMP 102 Programming Fundamentals I Presented by : Timture Choi.
CSC141- Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 31 Thanks for Lecture Slides: C How to Program by Paul Deital &
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.
1 CS161 Introduction to Computer Science Topic #4.
Chapter -7 Basic function of Input/output system basics and file processing Stream classes : I/O Streams. A stream is a source or destination for collection.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Spring 2013 Lecture 5: Continuing with output formatting.
Programming Fundamentals with C++1 Chapter 3 COMPLETING THE BASICS.
#include int main() { char *string1=”C++”; char *string2=”Program”; int m=strlen(string1); int n=strlen(string2); for(int i=1;i
1 COMS 261 Computer Science I Title: Functions Date: October 24, 2005 Lecture Number: 22.
1 Manipulators manipulators are used only in input and output statements endl, fixed, showpoint, setw, and setprecision are manipulators that can be used.
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.
Chapter 05 (Part II) Control Statements: Part II.
INPUT & OUTPUT 10/20/2016Department of Computer Science, UOM | Introduction | Fakhre Alam.
Standard Input - Output
CPS120: Introduction to Computer Science
Chapter 3 L7.
Chapter 21 - C++ Stream Input/Output Stream Manipulators
Output Stream Formatting
Chapter 21 - C++ Stream Input/Output
Math Library and IO formatting
Formatting Screen Input/Output
Manipulators CSCE 121 J. Michael Moore
Basic Input and Output C++ programs can read and write information using streams A simple input stream accepts typed data from a keyboard A simple output.
Chapter 5 Input and Output Streams
Formatting the Output The C++ standard library supplies many manipulators: endl, setw, fixed, showpoint, setprecesion. If we want to use endl, fixed, or.
Chapter 4 INPUT AND OUTPUT OBJECTS
Programming with ANSI C ++
C++ Stream Input/Output
Output Formatting Bina Ramamurthy 4/16/2019 BR.
Output Formatting Bina Ramamurthy 9/25/2019 BR.
Presentation transcript:

Programming Stream Manipulators

COMP102 Prog. Fundamentals I: Stream Manipulator Slide 2 Stream Manipulators in iostream.h Library I/O stream manipulators modify the behavior of insertions ( > ). l Examples: endl, flush oct, dec, hex (persistent effect: a change stays effective until another change is requested) int i = 10; cout << i << ” ” << i + i << endl; // cout << oct << i << ” ” << i + i << endl; // cout << hex << i << ” ” << i + i << ” ” << dec << i << endl; // a decimal: octal: Hexdecimal: a b c d e f

COMP102 Prog. Fundamentals I: Stream Manipulator Slide 3 Number Systems l Octal n Base 8 n 8 symbols l Hexadecimal n Base 16 n 16 symbols n More compact representation of the binary system Decimal Octal Hexadecimal A B F ED

COMP102 Prog. Fundamentals I: Stream Manipulator Slide 4 More Stream Manipulators in iomanip.h Library l #include Output manipulators (all except setw() are persistent): setprecision(d) - set number of significant digits to d ( d = 0 for default precision); enforce d decimal places by setting the I/O flag fixed setw(w) - set field width to w (or minimally larger than w to display the value correctly) setfill(c) - set fill character to c setiosflags(f) - set flag f to 1 resetiosflags(f) - set flag f to 0

COMP102 Prog. Fundamentals I: Stream Manipulator Slide 5 Formatting Flags (1/2) ios::fixed n Fixed-point notation (default: not set) Example: ios::scientific n Floating-point notation (default: not set) Example: 1.234e+001 ios::showpoint n Decimal point and trailing 0’s (default: not set) Example: 12.00

COMP102 Prog. Fundamentals I: Stream Manipulator Slide 6 Formatting Flags (2/2) ios::showpos A plus ( + ) sign is shown before positive numbers (default: not set) Example: +12 ios::right Right-justified format when used with setw() (default: set) ios::left Left-justified format when used with setw() (default: not set)