basic_fstream<chart, traits> / \ basic_ifstream<chart, traits> basic_ofstream<chart, traits>

Size: px
Start display at page:

Download "basic_fstream<chart, traits> / \ basic_ifstream<chart, traits> basic_ofstream<chart, traits>"

Transcription

1 The C++ I/O System I/O Class Hierarchy (simplified) ios_base ios / \ istream ostream \ / iostream ifstream fstream ofstream The class ios_base -- public variables and methods The derived classes istream, ostream, ifstream, ofstream Overloads of operators << and >> Manipulators The C++ I/O System The C++ I/O system defined in the IOStreams library is quite complex, extraordinarily useful and flexible, and quite beautiful in design. The current system resides in the namespace std, but is the result of at least a decade of evolution fuelled by theory, experiment, and the ISO standardization process. A comprehensive treatment of C++ IOStreams is well beyond the scope of these notes. In fact there is a very good 640 page treatise on the subject that is recommended for further study (see [Standard C++ IOStreams and Locales - Advanced Programmers Guide and Reference, by Angelika Langer and Klaus Kreft, Addison Wesley, 2000]). What is intended here is a detailed introduction to the most useful instantiations in this library, sufficient for most programming course work. For professional levels of expertise, you are strongly encouraged to obtain the Langer & Kreft reference and keep it alongside your Stroustrupp. A portion of the iostreams class hierarchy is shown in the slide. This is the portion that we will discuss in some detail. A more complete hierarchy is as follows: ios_base basic_ios<chart, traits> / \ basic_istream<chart, traits> basic_ostream<chart, traits> \ / basic_iostream<chart, traits> basic_ifstream<chart, traits> basic_ofstream<chart, traits> basic_fstream<chart, traits> Notice that all of the classes except the base class ios_base are templates. The two template parameters represent the character type being used along with properties of that type. There are two predefined character types, the familier 1- byte ascii characters char and the 4-byte wide characters wchar_t. The type char supports ASCII, EBCDIC, and ISO character sets. The type wchar_t supports Unicode and ISO The user can invent other character classes and associated traits and instantiate streams using that type. Even the diagram above does not illustrate the full generality of the IOStream library. There is support for internationalization in the form of Locales, and there is a hierarchy of buffer types that are used by iostreams. These are interesting and important features that are beyond the scope of these notes. There is also support for exception handling built into the class hierarchy shown above, but we will not say much about that aspect either. Because we will assume the standard ASCII character set, there is no need to go into detail on the traits classes in these notes. Finally, there is a parallel set of classes for I/O into strings instead of streams. To summarize, here is a list of advanced features of the IOStream library that we will not discuss in this chapter: Support for wide character sets and user-defined character sets Support for I/O exceptions Support for internationalization Support for I/O using std::string objects instead of buffers Support for iterators 1/12

2 For complete details on all these features of C++ IOStreams, see the Langer and Kreft reference. For most purposes, it suffices to use the ASCII character set and stream I/O, and there are type definitions in the standard library associated with those assumptions: typedef basic_ios < char, char_traits < char > > ios; typedef basic_istream < char, char_traits < char > > istream; typedef basic_ostream < char, char_traits < char > > ostream; typedef basic_iostream < char, char_traits < char > > iostream; typedef basic_ifstream < char, char_traits < char > > ifstream; typedef basic_ofstream < char, char_traits < char > > ofstream; typedef basic_fstream < char, char_traits < char > > fstream; Note that making these substitutions yields the hierarchy illustrated in the slide. In the remainder of this chapter we will discuss details of the classes ios_base (equivalently class ios), the derived classes istream, ostream, ifstream, ofstream, and the collection of IO manipulators defined with these classes. Class ios_base namespace std class ios_base // ios_base status methods // these read and/or manipulate the status bits bool fail () const; // true iff bad or fail state bool eof () const; // true iff stream is at end of file // ios_base binding methods ostream* tie (ostream*); // ties current stream to specified ostream // ios_base formatting methods format_flags setf (format_flags flags); // ios_base data methods int width(int val); char fill (char fillch); // ios_base enumerated bitmask types enum iostate ; // 4 io states, representing good, eof, bad, fail enum formatflags ; // 15 format flags, such as left, showpoint, hex enum openmode ; // 6 file open modes, such as in, out, binary enum seekdir ; // 3 file seek modes: beg, cur, end protected: unsigned long state; // stores status bits unsigned long flags; // stores flag bits unsigned long mode; // stores mode bits int widthvalue, // initialized to 0 precisionvalue; // initialized to 0 char fillcharacter; // initialized to ' ' streambuff* streambuffer; // pointer to a streambuff object // plus other data, such as specifying tied streams ; // end pseudo-definition of class ios_base // namespaced std Class ios_base I/O streams can be understood by exploring in detail the the class ios_base, which contains all of the public member variables and most public methods in the hierarchy. This slide shows the basic organization of the class. We explore the specifics in more detail in the following slides. Items to take note of at this point are: All of the standard library classes are in the std namespace. 2/12

3 The implementation details hinted at in this slide and elaborated later are not specified by the standard; we are illustrating one possible instantiation. Variables and methods related to exception handling are omitted. Understanding how streams work is greatly facilitated by following an instantiation of the base class ios_base from which all of the stream classes derive. A key to this understanding is the use of the enumerated types, which we discuss individually in the next slides. ios_base Status Methods class ios_base bool good () const; // true iff no error flag is set bool eof () const; // true iff eofbit is set bool fail () const; // true iff badbit or failbit are set bool bad () const; // true iff badbit is set bool operator! () const; // same as fail() operator void* () const; // null pointer if fail(), non-null otherwise void clear void setstate (iostate newstate = goodbit); // sets state to newstate (iostate addstate); // adds addstate to existing state, // i.e., the new state is oldstreamstate addstate enum iostate // io states goodbit = 0x0000, // everything is OK; not really a bit, but required to be 0 eofbit = 0x0001, // stream is at end of file failbit = 0x0002, // the last I/O operation failed, otherwise OK badbit = 0x0004 // a serious error has occurred, stream unusable ; protected: unsigned long state; // stores status bits ios_base Status Methods This slide shows one possible setup for the iostate enumerated type and the public member functions that use it. Some useful code techniques can be illuminated with this information. For example: std::ifstream in1; in1.open(filename); while (!in1) std::cout << "Cannot open file " << filename << " - try again: "; std::cin >> filename; in1.clear(); in1.open(filename); uses the! operator to detect a problem opening a file. This operator is defined for std::ifstream objects because std::ifstream is a public derived class of ios. You may also note that the interface allows client manipulation of the io states through both clear(state) and setstate(state). These differ in effect, as can be understood best by looking at the implementations: void std::ios::clear (iostate newstate) // default argument is goodbit state = newstate; void std::ios::setstate (iostate addstate) state = state addstate; // bitwise operation - set the designated bit 3/12

4 The implementation of setstate uses bitwise operations. These are native operations of C that allow direct access to integral values at the bit level. Most current CPUs have hardware support for bitwise operations, making them extremely efficient, typically requiring one clock cycle to accomplish the entire operation. We will return to bitwise operations in a later chapter. Meantime, here is a table showing the bitwise operations and their semantics: operation symbol type infix version accumulator version and & binary z = x & y z &= y or binary z = x y z = y xor ^ binary z = x ^ y z ^= y not ~ unary z = ~y (na) left shift << binary z = y << n (na) right shift >> binary z = y >> n (na) The line of code implementing setstate(addstate) would be equivalent to this bitwise arithmetic, if we had addstate = and state = and state = state addstate = = ios_base Formatting Methods class ios_base fmtflags flags () const; // returns current flags (interpret using enumerated type) fmtflags flags (fmtflags newflags); // sets flags to newflags; returns oldflags fmtflags setf (fmtflags setbits); // sets those flags specified in setbits; returns oldflags // called by iomanipulator setiosflags fmtflags setf (fmtflags setbits, fmtflags mask); // unsets flags in mask, then sets flags in setbits & mask // called by iomanipulator resetiosflags fmtflags unsetf (fmtflags unsetbits); // clears flags specified in unsetbits enum fmtflags // parameter for ios methods setf(), unsetf(), e.g., // setf(ios::right ios::dec ios::showpoint ios::fixed) skipws, left, right, internal, dec, oct, hex, showbase, showpoint, showpos, scientific, fixed, uppercase, unitbuf, boolalpha, adjustfield, basefield, floatfield ; protected: unsigned long flags; // stores flag bits ; ios_base Formatting Methods 4/12

5 Meaning of Format Flags enum fmtflags // parameter for ios_base methods setf(), unsetf(), e.g., // setf(ios_base::right ios_base::fixed) boolalpha = 0x0001, // reads and writes bool values in alphabetic left = 0x0002, // left-justify output right = 0x0004, // right-justify output internal = 0x0008, // (numeric output) prefix left..fill..number right skipws = 0x0010, // skip white space before extraction dec hex oct = 0x0020, // decimal = 0x0040, // hexadecimal = 0x0080, // octal // dec, oct, hex affect both input and output. On input, integral values // are interpreted in base notation and output uses appropirate mode. // Default is no bits set and means "C rules" apply: // output is decimal output and input of integral types is // interpreted as dec, oct, or hex depending leading/prefix: // (leading 1..9) => dec, (leading 0) => oct, (leading 0x) => hex showbase = 0x0100, // show base indicator on output (0 and 0x) showpoint = 0x0200, // show decimal point (for fixed point output) showpos = 0x0400, // out: force show of sign for positive numbers fixed = 0x0800, // out: force decimal notation for float scientific = 0x1000, // out: force scientific notation for float unitbuf = 0x2000, // out: flush buffer after each insertion uppercase = 0x4000, // out: use upper case indicators for hex and dec // convenience definitions: adjustfield = left right internal; basefield = dec hex oct; floatfield = scientific fixed; ; Meaning of Format Flags ios_base Data Methods class ios_base char fill (char fillch); // sets fill character (default = ' '); returns old fill_character; // called by iomanipulator setfill (char) int precision () const; // returns precision_value (>= 0) int precision (int val); // sets precision (default = 0, which means as precise as possible); // called by iomanipulator setprecision (int). int width () const; // returns width value (>= 0) int width (int val); // sets width_value; note: width reset to 0 after each extraction // called by iomanipulator setw (int) protected: int width_value, precision_value; // initialized to 0 char fill_character; // initialized to ' ' 5/12

6 ; ios_base Data Methods Meaning of Width and Precision // meaning of width (n) // n <= 0: no effect // n > 0: on output, sets minimum number of characters output // (filled with fill char) // on input, sets length of buffer for string extractions // Note: reset to 0 after each insertion and extraction // Called by manipulator setw (n) // meaning of precision (n) // n <= 0: default // n > 0: if ios::fixed bit is set, determines number of places // displayed after decimal point (forced if ios::showpoint // is also set) // if ios::fixed is not set, determines number of significant // digits displayed // Called by manipulator setprecision (n) Meaning of Width and Precision ios_base Binding Methods class ios_base streambuf* rdbuf (); // returns ptr to stream's streambuff object ostream* tie (); // returns ptr to the tied ostream ostream* tie (ostream*); // ties current stream to specified ostream, which is called the "tied // stream". Returns pointer to previously tied stream. // For an istream ist, this means that the tied stream will be // flushed whenever the ist needs input; for an ostream ost, this means that // the tied stream will be flushed whenever ost is flushed. // By default, cin is tied to cout. static bool sync_with_stdio (bool sync = true); // true causes cin, cerr, clog, cout to operate by means of the C standard I/O // connections stdin, stdout, and stderr; also implies unit buffering. // Returns previous value. // This is useful when mixing old C code with C++, otherwise not recommended. protected: streambuff* streambuffer; // pointer to a streambuff object ostream* tied_ostream; // pointer to an ostream object ; ios_base Binding Methods 6/12

7 ios_base File Modes class ios_base enum open_mode // open modes // optional second parameter to the fstream open() method, e.g., // open(filename, ios_base::out ios_base::binary) in = 0x0001, // open file for input -- read out = 0x0002, // open file for output -- write ate = 0x0004, // seek to eof when file is opened // -- "automatic to end" app = 0x0008, // open file in append mode // -- writing will occur at end trunc = 0x0010, // truncate the file if it exists binary = 0x0020 // open file in binary mode // -- write bytes only, no formatting characters ; enum seek_dir // file seek modes beg = 0x0100, // seek relative to beginning of file cur = 0x0200, // seek relative to current position end = 0x0400 // seek relative to end of file ; protected: unsigned long mode; // stores open and seek mode bits ; ios_base File Modes Meaning of File Modes Open Mode Effect Effect with ate in out out trunc out app in out in out trunc Opens text files for reading, initial position at beginning of file Truncates file to empty, or creates file, for write only Appends; opens or creates text file for writing at end of file Opens file for update (read or write), with position at beginning of file Opens file for update, truncates to empty Initial position is at end of file No effect on empty file No additional effect Position is at end of file No effect on empty file With the binary flag added ( binary), all conversions are suppressed. This is like a binary data copy. Meaning of File Modes 7/12

8 Possible ios_base Method Implementations ios_base::fmtflags ios_base::flags () const return flags; ios_base::fmtflags ios_base::flags (ios_base::fmtflags newflags) ios_base::fmtflags oldflags = flags; flags = newflags; return oldflags; ios_base::fmtflags ios_base::setf (ios_base::fmtflags setbits) ios_base::fmtflags oldflags = flags; flags = setbits; return oldflags; ios_base::fmtflags ios_base::setf (ios_base::fmtflags setbits, ios_base::fmtflags mask) ios_base::fmtflags oldflags = flags; flags = (flags & ~mask) (setbits & mask); // unsetf(mask); setf(setbits & mask); return oldflags; ios_base::fmtflags ios_base::unsetf (ios_base::fmtflags unsetbits) ios_base::fmtflags oldflags = flags; flags &= ~unsetbits; return oldflags; char ios_base::fill (char newfill) char oldfill = fill_character; fill_character = newfill; return oldfill; int ios_base::precision () const return precision_value; int ios_base::precision (int val); int oldprecision = precision_value; precision_value = val; return oldprecision; int ios_base::width () const return width_value; int ios_base::width (int val) int oldwidth = width_value; width_value = (val); return oldwidth; Possible ios_base Method Implementations 8/12

9 Class istream namespace std class istream : public class ios_base // overloads of input operator friend istream& operator >> (istream&, char); friend istream& operator >> (istream&, int); friend istream& operator >> (istream&, long); friend istream& operator >> (istream&, unsigned char); friend istream& operator >> (istream&, unsigned int); friend istream& operator >> (istream&, unsigned long); friend istream& operator >> (istream&, float); friend istream& operator >> (istream&, double); friend istream& operator >> (istream&, long double); friend istream& operator >> (istream&, char* ); // methods to access next element in stream char get (); void get (char&); char peek (); cin; // predefined object // namespace std Class istream Class ostream namespace std class ostream : public class ios_base // overloads of output operator friend ostream& operator << (ostream&, char); friend ostream& operator << (ostream&, int); friend ostream& operator << (ostream&, long); friend ostream& operator << (ostream&, unsigned char); friend ostream& operator << (ostream&, unsigned int); friend ostream& operator << (ostream&, unsigned long); friend ostream& operator << (ostream&, float); friend ostream& operator << (ostream&, double); friend ostream& operator << (ostream&, long double); friend ostream& operator << (ostream&, const char* ); // method to send element to stream void put(char ch); cout, cerr, clog; // predefined objects // namespace std Class ostream 9/12

10 Predefined Objects cin, cout, cerr, clog Predefined istream object: cin Predifined ostream objects: cout, cerr, clog Buffered ostreams: cout, clog Tied stream pair: cin, cout cin.tie(&cout); // in file iostream Predefined Objects cin, cout, cerr, clog Class ifstream class ifstream : public istream ifstream* open ( const char* filename, ios_base::open_mode mode = ios_base::in ); // opens file in specified mode, sets fail bit on failure // returns this on success, NULL on failure ifstream* close (); // closes file previously opened with open() // fails immediately if no file is currently open // sets fail bit if any operation fails // returns this on success, NULL on failure ; Class ifstream Class ofstream class ofstream : public ostream ofstream* open ( const char* filename, ios_base::open_mode mode = ios_base::out ios_base::trunc ); // opens file in specified mode, sets fail bit on failure // returns this on success, NULL on failure ofstream* close (); // flushes buffer, then closes file previously opened with open() // fails immediately if no file is currently open // sets fail bit if any operation fails // returns this on success, NULL on failure ; Class ofstream 10/12

11 I/O Manipulators - 1 // these take no parameters, defined in <iostream> boolalpha; // calls s.setf(ios::boolalpha) noboolalpha; // calls s.unsetf(ios::boolalpha) showbase; // calls s.setf(ios::showbase) noshowbase; // calls s.unsetf(ios::showbase) showpoint; // calls s.setf(ios::showpoint) noshowpoint; // calls s.unsetf(ios::showpoint) showpos; // calls s.setf(ios::showpos) noshowpos; // calls s.unsetf(ios::showpos) uppercase; // calls s.setf(ios::uppercase) nouppercase; // calls s.unsetf(ios::uppercase) skipws; // calls s.setf(ios::skipws) noskipws; // calls s.unsetf(ios::skipws) unitbuf; // calls s.setf(ios::unitbuf) nounitbuf; // calls s.unsetf(ios::unitbuf) left; // calls s.setf(ios::left, ios::adjustfield) right; // calls s.setf(ios::right, ios::adjustfield) internal; // calls s.setf(ios::internal, ios::adjustfield) dec; // calls setf(ios::dec, ios::basefield) hex; // calls setf(ios::hex, ios::basefield) oct; // calls setf(ios::oct, ios::basefield) fixed; // calls setf(ios::fixed, ios::floatfield) scientific; // calls setf(ios::scientific, ios::floatfield) endl; // flushes streambuff and inserts '\n' ends; // flushes streambuff and inserts '\0' flush; // flushes streambuff I/O Manipulators - 1 I/O Manipulators - 2 Prototype for 0-parameter manipulators: stream_type& manip_name (stream_type&); User can define and use manipulators, e.g.: // define: // use: ostream& beepbeep (ostream& os) std::cout << beepbeep << os << "\a\a"; return os; I/O Manipulators - 2 I/O Manipulators - 3 These manipulators take parameters and are more complicated to define the implementations use templates and function objects defined in <iomanip> setbase (int b); // sets base (radix) for numericals // b = 8, 10, 16 sets oct, dec, hex flag, respectively 11/12

12 // b = 0 means default: decimal on output, C rules for integers on input setiosflags (ios::format_flags mask); // calls ios::setf (mask) resetiosflags (ios::format_flags mask); // calls ios::unsetf (mask) setfill (char ch); // calls ios::fill (ch) setprecision (int n); // calls ios::precision (n) setw (int n); // calls ios::width (n) User may define a more extensive collection I/O Manipulators /12

Streams - Object input and output in C++

Streams - Object input and output in C++ Streams - Object input and output in C++ Dr. Donald Davendra Ph.D. Department of Computing Science, FEI VSB-TU Ostrava Dr. Donald Davendra Ph.D. (Department of Computing Streams - Object Science, input

More information

Module 11 The C++ I/O System

Module 11 The C++ I/O System Table of Contents Module 11 The C++ I/O System CRITICAL SKILL 11.1: Understand I/O streams... 2 CRITICAL SKILL 11.2: Know the I/O class hierarchy... 3 CRITICAL SKILL 11.3: Overload the > operators...

More information

Chapter 12 - C++ Stream Input/Output

Chapter 12 - C++ Stream Input/Output Chapter 12 - C++ Stream Input/Output 1 12.1 Introduction 12.2 Streams 12.2.1 Classic Streams vs. Standard Streams 12.2.2 iostream Library Header Files 12.2.3 Stream Input/Output Classes and Objects 12.3

More information

Piyush Kumar. input data. both cout and cin are data objects and are defined as classes ( type istream ) class

Piyush Kumar. input data. both cout and cin are data objects and are defined as classes ( type istream ) class C++ IO C++ IO All I/O is in essence, done one character at a time For : COP 3330. Object oriented Programming (Using C++) http://www.compgeom.com/~piyush/teach/3330 Concept: I/O operations act on streams

More information

The C++ Input/Output Class Hierarchy

The C++ Input/Output Class Hierarchy C++ Programming: The C++ Input/Output Class Hierarchy 2018 년도 2 학기 Instructor: Young-guk Ha Dept. of Computer Science & Engineering Contents Basics on C++ I/O The I/O class hierarchy The common base I/O

More information

by Pearson Education, Inc. All Rights Reserved. 2

by Pearson Education, Inc. All Rights Reserved. 2 The C++ standard libraries provide an extensive set of input/output capabilities. C++ uses type-safe I/O. Each I/O operation is executed in a manner sensitive to the data type. If an I/O member function

More information

CS2141 Software Development using C/C++ Stream I/O

CS2141 Software Development using C/C++ Stream I/O CS2141 Software Development using C/C++ Stream I/O iostream Two libraries can be used for input and output: stdio and iostream The iostream library is newer and better: It is object oriented It can make

More information

Chapter 21 - C++ Stream Input/Output

Chapter 21 - C++ Stream Input/Output Chapter 21 - C++ Stream Input/Output Outline 21.1 Introduction 21.2 Streams 21.2.1 Iostream Library Header Files 21.2.2 Stream Input/Output Classes and Objects 21.3 Stream Output 21.3.1 Stream-Insertion

More information

Chapter 21 - C++ Stream Input/Output

Chapter 21 - C++ Stream Input/Output Chapter 21 - C++ Stream Input/Output Outline 21.1 Introduction 21.2 Streams 21.2.1 Iostream Library Header Files 21.2.2 Stream Input/Output Classes and Objects 21.3 Stream Output 21.3.1 Stream-Insertion

More information

Standard I/O in C and C++

Standard I/O in C and C++ Introduction to Computer and Program Design Lesson 7 Standard I/O in C and C++ James C.C. Cheng Department of Computer Science National Chiao Tung University Standard I/O in C There three I/O memory buffers

More information

UNIT V FILE HANDLING

UNIT V FILE HANDLING UNIT V CONTENTS: Streams and formatted I/O I/O manipulators File handling Random access Object serialization Namespaces Std namespace ANSI String Objects Standard template library FILE HANDLING Streams:

More information

Fig: iostream class hierarchy

Fig: iostream class hierarchy Unit 6: C++ IO Systems ================== Streams: Θ A stream is a logical device that either produces or consumes information. Θ A stream is linked to a physical device by the I/O system. Θ All streams

More information

Java IO and C++ Streams

Java IO and C++ Streams Java IO and C++ Streams October 22, 2004 Operator Overloading in C++ - 2004-10-21 p. 1/31 Outline Java IO InputStream/OutputStream FilterInputStream/FilterOutputStream DataInputStream/DataOutputStream

More information

I/O Streams and Standard I/O Devices (cont d.)

I/O Streams and Standard I/O Devices (cont d.) 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 from the standard input device Learn how to use predefined

More information

Lecture 9. Introduction

Lecture 9. Introduction Lecture 9 File Processing Streams Stream I/O template hierarchy Create, update, process files Sequential and random access Formatted and raw processing Namespaces Lec 9 Programming in C++ 1 Storage of

More information

Introduction to C++ (Extensions to C)

Introduction to C++ (Extensions to C) Introduction to C++ (Extensions to C) C is purely procedural, with no objects, classes or inheritance. C++ is a hybrid of C with OOP! The most significant extensions to C are: much stronger type checking.

More information

Input and Output. Data Processing Course, I. Hrivnacova, IPN Orsay

Input and Output. Data Processing Course, I. Hrivnacova, IPN Orsay Input and Output Data Processing Course, I. Hrivnacova, IPN Orsay Output to the Screen Input from the Keyboard IO Headers Output to a File Input from a File Formatting I. Hrivnacova @ Data Processing Course

More information

UEE1303(1070) S 12 Object-Oriented Programming in C++

UEE1303(1070) S 12 Object-Oriented Programming in C++ Computational Intelligence on Automation Lab @ NCTU Learning Objectives UEE1303(1070) S 12 Object-Oriented Programming in C++ Lecture 06: Streams and File Input/Output I/O stream istream and ostream member

More information

IS 0020 Program Design and Software Tools

IS 0020 Program Design and Software Tools 1 IS 0020 Program Design and Software Tools Stack/Queue - File Processing Lecture 10 March 29, 2005 Introduction 2 Storage of data Arrays, variables are temporary Files are permanent Magnetic disk, optical

More information

Chapter 8 File Processing

Chapter 8 File Processing Chapter 8 File Processing Outline 1 Introduction 2 The Data Hierarchy 3 Files and Streams 4 Creating a Sequential Access File 5 Reading Data from a Sequential Access File 6 Updating Sequential Access Files

More information

Physics 6720 I/O Methods October 30, C++ and Unix I/O Streams

Physics 6720 I/O Methods October 30, C++ and Unix I/O Streams Physics 6720 I/O Methods October 30, 2002 We have been using cin and cout to handle input from the keyboard and output to the screen. In these notes we discuss further useful capabilities of these standard

More information

Rogue Wave Standard C++ Library Iostreams and Locale User s Reference

Rogue Wave Standard C++ Library Iostreams and Locale User s Reference Rogue Wave Standard C++ Library Iostreams and Locale User s Reference (Part B) Rogue Wave Software Corvallis, Oregon USA Copyright 1996 Rogue Wave Software, Inc. All rights reserved. Rogue Wave Standard

More information

Fundamentals of Programming Session 27

Fundamentals of Programming Session 27 Fundamentals of Programming Session 27 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2013 These slides have been created using Deitel s slides Sharif University of Technology Outlines

More information

Chapter 3 - Notes Input/Output

Chapter 3 - Notes Input/Output Chapter 3 - Notes Input/Output I. I/O Streams and Standard I/O Devices A. I/O Background 1. Stream of Bytes: A sequence of bytes from the source to the destination. 2. 2 Types of Streams: i. Input Stream:

More information

C++ Input/Output: Streams

C++ Input/Output: Streams C++ Input/Output: Streams Basic I/O 1 The basic data type for I/O in C++ is the stream. C++ incorporates a complex hierarchy of stream types. The most basic stream types are the standard input/output streams:

More information

10/23/02 21:20:33 IO_Examples

10/23/02 21:20:33 IO_Examples 1 Oct 22 22:07 2000 extractor1.c Page 1 istream &operator>>( istream &in, Point &p ){ char junk; in >> junk >> p.x >> junk >> p.y >> junk; return in; 2 Oct 22 22:07 2000 extractor2.c Page 1 istream &operator>>(

More information

Chapter 12. Streams and File I/O. Copyright 2010 Pearson Addison-Wesley. All rights reserved

Chapter 12. Streams and File I/O. Copyright 2010 Pearson Addison-Wesley. All rights reserved Chapter 12 Streams and File I/O Copyright 2010 Pearson Addison-Wesley. All rights reserved Learning Objectives I/O Streams File I/O Character I/O Tools for Stream I/O File names as input Formatting output,

More information

Object Oriented Programming Using C++ UNIT-3 I/O Streams

Object Oriented Programming Using C++ UNIT-3 I/O Streams File - The information / data stored under a specific name on a storage device, is called a file. Stream - It refers to a sequence of bytes. Text file - It is a file that stores information in ASCII characters.

More information

C++ Programming Lecture 10 File Processing

C++ Programming Lecture 10 File Processing C++ Programming Lecture 10 File Processing By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department Outline Introduction. The Data Hierarchy. Files and Streams. Creating a Sequential

More information

File I/O Christian Schumacher, Info1 D-MAVT 2013

File I/O Christian Schumacher, Info1 D-MAVT 2013 File I/O Christian Schumacher, chschuma@inf.ethz.ch Info1 D-MAVT 2013 Input and Output in C++ Stream objects Formatted output Writing and reading files References General Remarks I/O operations are essential

More information

Lab 6. Review of Variables, Formatting & Loops By: Dr. John Abraham, Professor, UTPA

Lab 6. Review of Variables, Formatting & Loops By: Dr. John Abraham, Professor, UTPA Variables: Lab 6 Review of Variables, Formatting & Loops By: Dr. John Abraham, Professor, UTPA We learned that a variable is a name assigned to the first byte of the necessary memory to store a value.

More information

Stream States. Formatted I/O

Stream States. Formatted I/O C++ Input and Output * the standard C++ library has a collection of classes that can be used for input and output * most of these classes are based on a stream abstraction, the input or output device is

More information

Input/Output Streams: Customizing

Input/Output Streams: Customizing DM560 Introduction to Programming in C++ Input/Output Streams: Customizing Marco Chiarandini Department of Mathematics & Computer Science University of Southern Denmark [Based on slides by Bjarne Stroustrup]

More information

Chapter 11 Customizing I/O

Chapter 11 Customizing I/O Chapter 11 Customizing I/O Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/~hkaiser/fall_2010/csc1253.html Slides adapted from: Bjarne Stroustrup, Programming Principles and Practice using C++

More information

Objects and streams and files CS427: Elements of Software Engineering

Objects and streams and files CS427: Elements of Software Engineering Objects and streams and files CS427: Elements of Software Engineering Lecture 6.2 (C++) 10am, 13 Feb 2012 CS427 Objects and streams and files 1/18 Today s topics 1 Recall...... Dynamic Memory Allocation...

More information

Chapter Overview. I/O Streams as an Introduction to Objects and Classes. I/O Streams. Streams and Basic File I/O. Objects

Chapter Overview. I/O Streams as an Introduction to Objects and Classes. I/O Streams. Streams and Basic File I/O. Objects Chapter 6 I/O Streams as an Introduction to Objects and Classes Overview 6.1 Streams and Basic File I/O 6.2 Tools for Stream I/O 6.3 Character I/O Copyright 2008 Pearson Addison-Wesley. All rights reserved.

More information

Fundamentals of Programming Session 25

Fundamentals of Programming Session 25 Fundamentals of Programming Session 25 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2013 These slides have been created using Deitel s slides Sharif University of Technology Outlines

More information

CS11 Advanced C++ Lecture 2 Fall

CS11 Advanced C++ Lecture 2 Fall CS11 Advanced C++ Lecture 2 Fall 2006-2007 Today s Topics C++ strings Access Searching Manipulation Converting back to C-style strings C++ streams Error handling Reading unformatted character data Simple

More information

Chapter 11 Customizing I/O

Chapter 11 Customizing I/O Chapter 11 Customizing I/O Bjarne Stroustrup www.stroustup.com/programming Overview Input and output Numeric output Integer Floating point File modes Binary I/O Positioning String streams Line-oriented

More information

CS201 Solved MCQs.

CS201 Solved MCQs. 15.1 Answer each of the following: a. Input/output in C++ occurs as of bytes. b. The stream manipulators that format justification are, and. c. Member function can be used to set and reset format state.

More information

Strings and Streams. Professor Hugh C. Lauer CS-2303, System Programming Concepts

Strings and Streams. Professor Hugh C. Lauer CS-2303, System Programming Concepts Strings and Streams Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++, by Walter

More information

Chapter 6. I/O Streams as an Introduction to Objects and Classes. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Chapter 6. I/O Streams as an Introduction to Objects and Classes. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 I/O Streams as an Introduction to Objects and Classes Overview 6.1 Streams and Basic File I/O 6.2 Tools for Stream I/O 6.3 Character I/O Slide 6-3 6.1 Streams and Basic File I/O I/O Streams I/O

More information

Object-Oriented Programming in C++ Overview. Example. (Course Computer Systems ) 1. Overview. Wolfgang Schreiner

Object-Oriented Programming in C++ Overview. Example. (Course Computer Systems ) 1. Overview. Wolfgang Schreiner Object-Oriented Programming in C++ (Course Computer Systems ) Wolfgang Schreiner Wolfgang.Schreiner@risc.jku.at Research Institute for Symbolic Computation (RISC) Johannes Kepler University, Linz, Austria

More information

Chapter 12. Streams and File I/O. Copyright 2016 Pearson, Inc. All rights reserved.

Chapter 12. Streams and File I/O. Copyright 2016 Pearson, Inc. All rights reserved. Chapter 12 Streams and File I/O Copyright 2016 Pearson, Inc. All rights reserved. Learning Objectives I/O Streams File I/O Character I/O Tools for Stream I/O File names as input Formatting output, flag

More information

Object-Oriented Programming in C++

Object-Oriented Programming in C++ Object-Oriented Programming in C++ (Course Computer Systems ) Wolfgang Schreiner Wolfgang.Schreiner@risc.jku.at Research Institute for Symbolic Computation (RISC) Johannes Kepler University, Linz, Austria

More information

Lecture 3. Input and Output. Review from last week. Variable - place to store data in memory. identified by a name should be meaningful Has a type-

Lecture 3. Input and Output. Review from last week. Variable - place to store data in memory. identified by a name should be meaningful Has a type- Lecture 3 Input and Output Review from last week Variable - place to store data in memory identified by a name should be meaningful Has a type- int double char bool Has a value may be garbage change value

More information

Chapter 12. Streams and File I/O

Chapter 12. Streams and File I/O Chapter 12 Streams and File I/O Learning Objectives I/O Streams File I/O Character I/O Tools for Stream I/O File names as input Formatting output, flag settings Introduction Streams Special objects Deliver

More information

What we will learn about this week:

What we will learn about this week: What we will learn about this week: Streams Basic file I/O Tools for Stream I/O Manipulators Character I/O Get and Put EOF function Pre-defined character functions Objects 1 I/O Streams as an Introduction

More information

CS3157: Advanced Programming. Outline

CS3157: Advanced Programming. Outline CS3157: Advanced Programming Lecture #12 Apr 3 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline Intro CPP Boring stuff: Language basics: identifiers, data types, operators, type conversions, branching

More information

Introduction to Standard C++ Console I/O. C++ Object Oriented Programming Pei-yih Ting NTOU CS

Introduction to Standard C++ Console I/O. C++ Object Oriented Programming Pei-yih Ting NTOU CS Introduction to Standard C++ Console I/O C++ Object Oriented Programming Pei-yih Ting NTOU CS 1 Contents I/O class hierarchy, cin, cout > operators Buffered I/O cin.get() and cin.getline() status

More information

Chapter 11 Customizing I/O

Chapter 11 Customizing I/O Chapter 11 Customizing I/O Bjarne Stroustrup www.stroustrup.com/programming Overview Input and output Numeric output Integer Floating point File modes Binary I/O Positioning String streams Line-oriented

More information

Jan 27, C++ STL Streams. Daniel Maleike

Jan 27, C++ STL Streams. Daniel Maleike C++ STL Streams Why Stream-IO? The STL way for I/O Input, output, formatting, file access More type-safe than printf(), scanf() Extensible with user defined types (classes) Inheritable, i.e. custom I/O

More information

Chapter 15 - C++ As A "Better C"

Chapter 15 - C++ As A Better C Chapter 15 - C++ As A "Better C" Outline 15.1 Introduction 15.2 C++ 15.3 A Simple Program: Adding Two Integers 15.4 C++ Standard Library 15.5 Header Files 15.6 Inline Functions 15.7 References and Reference

More information

CSE 100: STREAM I/O, BITWISE OPERATIONS, BIT STREAM I/O

CSE 100: STREAM I/O, BITWISE OPERATIONS, BIT STREAM I/O CSE 100: STREAM I/O, BITWISE OPERATIONS, BIT STREAM I/O PA2: encoding/decoding ENCODING: 1.Scan text file to compute frequencies 2.Build Huffman Tree 3.Find code for every symbol (letter) 4.Create new

More information

Object-Oriented Programming in C++ Overview. Example. (Course Computer Systems ) 1. Overview. Wolfgang Schreiner

Object-Oriented Programming in C++ Overview. Example. (Course Computer Systems ) 1. Overview. Wolfgang Schreiner Object-Oriented Programming in C++ (Course Computer Systems ) Wolfgang Schreiner Wolfgang.Schreiner@risc.jku.at Research Institute for Symbolic Computation (RISC) Johannes Kepler University, Linz, Austria

More information

Consider the following example where a base class has been derived by other two classes:

Consider the following example where a base class has been derived by other two classes: Class : BCA 3rd Semester Course Code: BCA-S3-03 Course Title: Object Oriented Programming Concepts in C++ Unit IV Polymorphism The word polymorphism means having many forms. Typically, polymorphism occurs

More information

We will exclusively use streams for input and output of data. Intro Programming in C++

We will exclusively use streams for input and output of data. Intro Programming in C++ C++ Input/Output: Streams The basic data type for I/O in C++ is the stream. C++ incorporates a complex hierarchy of stream types. The most basic stream types are the standard input/output streams: 1 istream

More information

Lecture 5 Files and Streams

Lecture 5 Files and Streams Lecture 5 Files and Streams Introduction C programs can store results & information permanently on disk using file handling functions These functions let you write either text or binary data to a file,

More information

COMP322 - Introduction to C++

COMP322 - Introduction to C++ COMP322 - Introduction to C++ Lecture 05 - I/O using the standard library, stl containers, stl algorithms Dan Pomerantz School of Computer Science 5 February 2013 Basic I/O in C++ Recall that in C, we

More information

OBJECT ORIENTED DESIGN WITH C++ AN INTRODUCTION

OBJECT ORIENTED DESIGN WITH C++ AN INTRODUCTION OBJECT ORIENTED DESIGN WITH C++ AN INTRODUCTION Software is a collection of programs. Program is a set of statements that performs a specific task. Since the invention of the computer, many programming

More information

Streams. Rupesh Nasre.

Streams. Rupesh Nasre. Streams Rupesh Nasre. OOAIA January 2018 I/O Input stream istream cin Defaults to keyboard / stdin Output stream ostream cout std::string name; std::cout > name; std::cout

More information

BITG 1233: Introduction to C++

BITG 1233: Introduction to C++ BITG 1233: Introduction to C++ 1 Learning Outcomes At the end of this lecture, you should be able to: Identify basic structure of C++ program (pg 3) Describe the concepts of : Character set. (pg 11) Token

More information

Engineering Problem Solving with C++, Etter/Ingber

Engineering Problem Solving with C++, Etter/Ingber Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs C++, Second Edition, J. Ingber 1 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input

More information

Introduction. Lecture 5 Files and Streams FILE * FILE *

Introduction. Lecture 5 Files and Streams FILE * FILE * Introduction Lecture Files and Streams C programs can store results & information permanently on disk using file handling functions These functions let you write either text or binary data to a file, and

More information

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++, by Walter

More information

The C++ Language. Output. Input and Output. Another type supplied by C++ Very complex, made up of several simple types.

The C++ Language. Output. Input and Output. Another type supplied by C++ Very complex, made up of several simple types. The C++ Language Input and Output Output! Output is information generated by a program.! Frequently sent the screen or a file.! An output stream is used to send information. Another type supplied by C++

More information

Advanced I/O Concepts

Advanced I/O Concepts Advanced Object Oriented Programming Advanced I/O Concepts Seokhee Jeon Department of Computer Engineering Kyung Hee University jeon@khu.ac.kr 1 1 Streams Diversity of input sources or output destinations

More information

COMP322 - Introduction to C++

COMP322 - Introduction to C++ COMP322 - Introduction to C++ Winter 2011 Lecture 05 - I/O using the standard library & Introduction to Classes Milena Scaccia School of Computer Science McGill University February 1, 2011 Final note on

More information

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018 C++ Basics Lecture 2 COP 3014 Spring 2018 January 8, 2018 Structure of a C++ Program Sequence of statements, typically grouped into functions. function: a subprogram. a section of a program performing

More information

Convenient way to deal large quantities of data. Store data permanently (until file is deleted).

Convenient way to deal large quantities of data. Store data permanently (until file is deleted). FILE HANDLING Why to use Files: Convenient way to deal large quantities of data. Store data permanently (until file is deleted). Avoid typing data into program multiple times. Share data between programs.

More information

Week 3: File I/O and Formatting 3.7 Formatting Output

Week 3: File I/O and Formatting 3.7 Formatting Output Week 3: File I/O and Formatting 3.7 Formatting Output Formatting: the way a value is printed: Gaddis: 3.7, 3.8, 5.11 CS 1428 Fall 2014 Jill Seaman spacing decimal points, fractional values, number of digits

More information

I BSc(IT) [ Batch] Semester II Core: Object Oriented Programming With C plus plus - 212A Multiple Choice Questions.

I BSc(IT) [ Batch] Semester II Core: Object Oriented Programming With C plus plus - 212A Multiple Choice Questions. Dr.G.R.Damodaran College of Science (Autonomous, affiliated to the Bharathiar University, recognized by the UGC)Reaccredited at the 'A' Grade Level by the NAAC and ISO 9001:2008 Certified CRISL rated 'A'

More information

Chapter 2. Outline. Simple C++ Programs

Chapter 2. Outline. Simple C++ Programs Chapter 2 Simple C++ Programs Outline Objectives 1. Building C++ Solutions with IDEs: Dev-cpp, Xcode 2. C++ Program Structure 3. Constant and Variables 4. C++ Operators 5. Standard Input and Output 6.

More information

[CSE10200] Programming Basis ( 프로그래밍기초 ) Chapter 7. Seungkyu Lee. Assistant Professor, Dept. of Computer Engineering Kyung Hee University

[CSE10200] Programming Basis ( 프로그래밍기초 ) Chapter 7. Seungkyu Lee. Assistant Professor, Dept. of Computer Engineering Kyung Hee University [CSE10200] Programming Basis ( 프로그래밍기초 ) Chapter 7 Seungkyu Lee Assistant Professor, Dept. of Computer Engineering Kyung Hee University Input entities Keyboard, files Output entities Monitor, files Standard

More information

CHAPTER 3 Expressions, Functions, Output

CHAPTER 3 Expressions, Functions, Output CHAPTER 3 Expressions, Functions, Output More Data Types: Integral Number Types short, long, int (all represent integer values with no fractional part). Computer Representation of integer numbers - Number

More information

Chapter 3. Numeric Types, Expressions, and Output

Chapter 3. Numeric Types, Expressions, and Output Chapter 3 Numeric Types, Expressions, and Output 1 Chapter 3 Topics Constants of Type int and float Evaluating Arithmetic Expressions Implicit Type Coercion and Explicit Type Conversion Calling a Value-Returning

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

Introduction to C++ Systems Programming

Introduction to C++ Systems Programming Introduction to C++ Systems Programming Introduction to C++ Syntax differences between C and C++ A Simple C++ Example C++ Input/Output C++ Libraries C++ Header Files Another Simple C++ Example Inline Functions

More information

Setting Justification

Setting Justification Setting Justification Formatted I/O 1 Justification - Justification refers to the alignment of data within a horizontal field. - The default justification in output fields is to the right, with padding

More information

JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli (An approved by AICTE and Affiliated to Anna University)

JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli (An approved by AICTE and Affiliated to Anna University) Estd: 1994 JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli - 621014 (An approved by AICTE and Affiliated to Anna University) ISO 9001:2000 Certified Subject Code & Name : CS 1202

More information

This chapter introduces the notion of namespace. We also describe how to manage input and output with C++ commands via the terminal or files.

This chapter introduces the notion of namespace. We also describe how to manage input and output with C++ commands via the terminal or files. C++ PROGRAMMING LANGUAGE: NAMESPACE AND MANGEMENT OF INPUT/OUTPUT WITH C++. CAAM 519, CHAPTER 15 This chapter introduces the notion of namespace. We also describe how to manage input and output with C++

More information

Operator Overloading in C++ Systems Programming

Operator Overloading in C++ Systems Programming Operator Overloading in C++ Systems Programming Operator Overloading Fundamentals of Operator Overloading Restrictions on Operator Overloading Operator Functions as Class Members vs. Global Functions Overloading

More information

Chapter 3 : Assignment and Interactive Input (pp )

Chapter 3 : Assignment and Interactive Input (pp ) Page 1 of 50 Printer Friendly Version User Name: Stephen Castleberry email Id: scastleberry@rivercityscience.org Book: A First Book of C++ 2007 Cengage Learning Inc. All rights reserved. No part of this

More information

n1099 Document No.: J16/ WG21/N1099 Date: 17 July 1997 Programming Language C++

n1099 Document No.: J16/ WG21/N1099 Date: 17 July 1997 Programming Language C++ Document No.: J16/97-0061 WG21/N1099 Date: 17 July 1997 Project: Reply-To: Programming Language C++ Steve Rumsby steve@maths.warwick.ac.uk Iostreams WP changes for London ===============================

More information

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi Modern C++ for Computer Vision and Image Processing Igor Bogoslavskyi Outline Classes Polymorphism I/O Stringstreams CMake find_package 2 Polymorphism From Greek polys, "many, much" and morphē, "form,

More information

Jayaram college of Engineering and Technology, Pagalavadi. CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT

Jayaram college of Engineering and Technology, Pagalavadi. CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT Two Mark Questions UNIT - I 1. DEFINE ENCAPSULATION. Encapsulation is the process of combining data and functions

More information

Contents. 1 Introduction to Computers, the Internet and the World Wide Web 1. 2 Introduction to C Programming 26

Contents. 1 Introduction to Computers, the Internet and the World Wide Web 1. 2 Introduction to C Programming 26 Preface xix 1 Introduction to Computers, the Internet and the World Wide Web 1 1.1 Introduction 2 1.2 What Is a Computer? 4 1.3 Computer Organization 4 1.4 Evolution of Operating Systems 5 1.5 Personal,

More information

cs3157: c++ lecture #2 (mon-11-apr-2005) chronology of some programming languages... C++ vs Java identifiers.

cs3157: c++ lecture #2 (mon-11-apr-2005) chronology of some programming languages... C++ vs Java identifiers. cs3157: c++ lecture #2 (mon-11-apr-2005) chronology of some programming languages... today: language basics: identifiers, data types, operators, type conversions, branching and looping, program structure

More information

IBM. C/C++ Legacy Class Libraries Reference SC

IBM. C/C++ Legacy Class Libraries Reference SC IBM C/C++ Legacy Class Libraries Reference SC09-7652-02 IBM C/C++ Legacy Class Libraries Reference SC09-7652-02 Note! Before using this information and the product it supports, read the information in

More information

Intermediate Programming Methodologies in C++ CIS22B. Joe Bentley

Intermediate Programming Methodologies in C++ CIS22B. Joe Bentley Intermediate Programming Methodologies in C++ CIS22B Joe Bentley DeAnzaCollege Computer Information System September 2018 Table of Contents Review...3 CIS22A Basics...3 An Old CIS22A Midterm... 3 Warning

More information

Getting started with C++ (Part 2)

Getting started with C++ (Part 2) Getting started with C++ (Part 2) CS427: Elements of Software Engineering Lecture 2.2 11am, 16 Jan 2012 CS427 Getting started with C++ (Part 2) 1/22 Outline 1 Recall from last week... 2 Recall: Output

More information

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING CS6456 OBJECT ORIENTED PROGRAMMING

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING CS6456 OBJECT ORIENTED PROGRAMMING DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING CS6456 OBJECT ORIENTED PROGRAMMING Unit I : OVERVIEW PART A (2 Marks) 1. Give some characteristics of procedure-oriented

More information

Object Oriented Programming In C++

Object Oriented Programming In C++ C++ Question Bank Page 1 Object Oriented Programming In C++ 1741059 to 1741065 Group F Date: 31 August, 2018 CIA 3 1. Briefly describe the various forms of get() function supported by the input stream.

More information

Chapter 14 Sequential Access Files

Chapter 14 Sequential Access Files Chapter 14 Sequential Access Files Objectives Create file objects Open a sequential access file Determine whether a sequential access file was opened successfully Write data to a sequential access file

More information

Contents. 2 Introduction to C++ Programming,

Contents. 2 Introduction to C++ Programming, cppfp2_toc.fm Page vii Thursday, February 14, 2013 9:33 AM Chapter 24 and Appendices F K are PDF documents posted online at www.informit.com/title/9780133439854 Preface xix 1 Introduction 1 1.1 Introduction

More information

c++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords.

c++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords. Chapter 1 File Extensions: Source code (cpp), Object code (obj), and Executable code (exe). Preprocessor processes directives and produces modified source Compiler takes modified source and produces object

More information

THE INTEGER DATA TYPES. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

THE INTEGER DATA TYPES. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski) THE INTEGER DATA TYPES STORAGE OF INTEGER TYPES IN MEMORY All data types are stored in binary in memory. The type that you give a value indicates to the machine what encoding to use to store the data in

More information

File I/O. File Names and Types. I/O Streams. Stream Extraction and Insertion. A file name should reflect its contents

File I/O. File Names and Types. I/O Streams. Stream Extraction and Insertion. A file name should reflect its contents File I/O 1 File Names and Types A file name should reflect its contents Payroll.dat Students.txt Grades.txt A file s extension indicates the kind of data the file holds.dat,.txt general program input or

More information

Overview of Lecture. 1 Overloading I/O Operators. 2 Overloading << and >> for Fractions. 3 Formatted vs Unformatted Input

Overview of Lecture. 1 Overloading I/O Operators. 2 Overloading << and >> for Fractions. 3 Formatted vs Unformatted Input Overview of Lecture 1 Overloading I/O Operators 2 Overloading > for Fractions 3 Formatted vs Unformatted Input 4 Setting the State of a Stream 5 Questions PIC 10B Streams, Part II April 20, 2016

More information

C++ As A "Better C" Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan.

C++ As A Better C Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan. C++ As A "Better C" Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2013 Fall Outline 15.2 C++ 15.3 A Simple Program: Adding Two Integers 15.5

More information