Module C++ I/O System Basics

Size: px
Start display at page:

Download "Module C++ I/O System Basics"

Transcription

1 1 Module - 36 C++ I/O System Basics Table of Contents 1. Introduction 2. Stream classes of C++ 3. Predefined Standard Input/Output Streams 4. Functions of <istream> class 5. Functions of <ostream> class 6. Summary

2 2 Learning outcome After studying this module, you will be able to: 1. Learn about Stream classes of C++ 2. Know about Predefined Standard Input/Output Streams 3. Study about Functions of <istream> class 4. Study about Functions of <ostream> class 1. Introduction In C++, the Input/output is offered as a component of the standard library. The C++ standard libraries present widespread set of input/output facilities which are most commonly used for I/O operations. The Input/output in C++ language mostly occurs in streams, which are nothing but sequences of bytes. In general, the streams perform two types of operations, they are Input operation and Output operation. 2. Stream classes of C++ C++ includes a hierarchy of classes called as Stream classes that are mainly used to describe various streams to deal with console and disk files. The stream classes are stated in the iostream or iostream.h header file. The stream classes of C++ are: INPUT POINTER OUTPUT ios istream streambuf ostream iostream istream_withassign iostream_withassign ostream_withassign

3 From the above figure: It is clear that ios is the base class for the istream, i.e., Input stream and base class for ostream, i.e., Output stream. The istream and ostream classes are in turn base classes for the class iostream, i.e., Input/Output Stream. The stream classes and their functionality can be represented in the table as follows: 3 Stream class ios class istream class ostream class streambuf class _withassign classes filebuf class strstreambuf class Functionality and their Description It offers the basic services that are used by all input and output classes. In addition, it provides a pointer to a buffer object, i.e., streambuf object. It tries to inherit the properties from the base class ios. It offers the services for input methods. In the usual manner, it provides a mechanism to accept the data from the input device. It declare the input functions such as get(), getline(), read() and it also include overloaded extraction operator (>>). It tries to inherit the properties from the base class ios. It offers the services for output methods. In the usual manner, it provides a mechanism to displa y the data to the output device. It declare the output functions such as put(), write() and it also include overloaded insertion operator (<<). It tries to provide memory for a buffer. It also provides the methods of the class for loading the contents of the buffer, access the contents of the buffer, flush the contents of the buffer, organizing the memory of the buffer. It also holds the mainly important and primitive functions for the streams on a First- In-First-Out Order basis. C++ language consists of 3 _withassign classes, they are istream_withassign, ostream_withassign and iostream_withassign. The istream_withassign is a derived class which is derived from base class istream class. The ostreamwithassign is a derived class which is derived from base class ostream class. The iostreamwithassign is a derived class which is derived from base class iostream class. The _withassign classes basically consist of assignment operators. By using the assignment operators, it is possible to copy the objects of the _withassign classes. By making the assignment operators as private, the copying on istream, ostream and iostream classes can be stopped. It is a derived class which is inherited from the base class streambuf. It tries to present the necessary and basic operations that are related to files. It is a derived class which is inherited from the base class streambuf. It is mainly designed to hold the buffers that are related to memory. 3. Predefined Standard Input/Output Streams C++ language consists of four streams that are mainly defined for standard Input/Output. The two operators, i.e., extraction operator (>>) and insertion operator (<<) are overloaded and are defined on basic or primary data types. It is also possible to overload the extraction and insertion operators on the user-defined datatypes, but it can be possible for specific objects of the class.

4 4 The four streams are: cin: It is mainly used to get the input from standard input device, such as keyboard. cout: It is mainly used to display the output to standard output device, such as monitor or screen. cerr: It is mainly used for standard error to display on monitor or screen. clog: It is mainly used for buffered error to display on monitor. 3.1 Standard Input Stream (cin) The istream class supports the methods for input of formatted data as well as unformatted data. The cin object of istream class along with extraction operator ( >>) is mainly used for the input of primary types. It is possible with the cin object to overload the extraction operator (>>) for the user defined types, but it can be used for the class of input object. In general, the operator (>>) is basically, the bitwise right shift operator which is overloaded to do the process of extraction operation. Since, after each and every extraction operation, the extraction operator tries to send a reference back to cin, therefore, it allows cascading operation and it is possible to extract a quantity of values written one after another and each of them lead by extraction operator. cin >> variable1 >> varibale2... >> variablen; In the above syntax: The variable1, variable2,, variablen are valid C++ variable names. cin>>rollno>>name>>total; Program to illustrate the usage of cin object and extraction operator (>>) #include<iostream> int number1 ; double number2 ; char ch1 ; char Grade [30]; cout <<"Enter value of Number1 : " ; cin >>number1; cout <<"Enter the value of Number2 : "; cin >>number2; cout <<"Enter the value of ch1 : "; cin>>ch1 ; cout<<"enter a Grade : "; cin >> Grade ; cout <<"The data that is entered is "<<endl; cout <<"Number1 = "<<number1 <<", Number2 = "<<number2 <<", ch1 = "<<ch1 <<", Grade = " <<Grade <<endl;

5 5 Enter value of Number1 : 10 Enter the value of Number2 : -20 Enter the value of ch1 : Z Enter a Grade : Excellent The data that is entered is Number1 = 10, Number2 = -20, ch1 = Z, Grade = Excellent 3.2 Standard Output Stream The cout object of ostream class is used for standard output along with overloaded insertion operator (<<). To do the process of insertion operation of basic data type, the operator <<, i.e., bitwise left shift binary operator is overloaded. The cout object can be used for user defined data, but it is must that the overloading functions for operator << are to be described by the programmer for the class of the objects being that are dealt with. Since, after each and every insertion operation, the insertion operator tries to return the value of reference to the object of ostream class, i.e., cout, therefore, it allows the cascading of stream objects which helps to write a number of outputs in the same output statement. cout << item1 << item2 << << itemn; In the above syntax: The item1, item2,,itemn can be variables of fundamental data type or constants of fundamental data type. cout<<nameofcustomer<<" paid rupees "<<Price<<" for "<< Custno <<" Mangoes " <<endl; Program to illustrate the use of cout object and insertion operator (<<) #include<iostream> int Custno =401; double Price =1000.5; char flag = 'F'; char Nameofcustomer[] = "Deepali"; cout << "flag is "<<flag<<endl; cout<<nameofcustomer<<" paid rupees "<<Price<<" for "<< Custno <<" Mangoes " <<endl; flag is F Deepali paid rupees for 401 Mangoes

6 6 3.3 Standard Error Stream (cerr) The cerr, which is a predefined object is an instance of ostream class that corresponds to the standard error stream. It is related with the cstdio stream stderr. The cerr object is said to be connected to the standard error device, which is a display screen or monitor, but, since, the cerr object is un-buffered, therefore, each stream insertion to cerr causes its output to come into view instantly. The cerr object can also be used in combination with the stream insertion operator. By default, most of the systems have their regular error output which is set to the console, where the text messages are displayed, even though this can normally be forwarded. Because cerr is an predefined object of ostream class, it is possible to write the characters to it either as formatted data with the help of the insertion operator (<<) or as unformatted data with the help of the write member function. Program to illustrate the usage of standard error stream (cerr) #include <iostream > int main( ) char text[] = "Unable to read the content"; cerr << "Error message : " << text << endl; Error message : Unable to read the content 3.4 clog The clog which is a predefined object is an instance of ostream class which represents the standard logging stream. The clog object is said to be connected to the standard error device, which is a display screen, but because, the predefined object clog is buffered, therefore, each insertion to clog might effects its output to be seized in a buffer until the buffer is full or until the buffer is flushed. The clog object can also be used in combination with the stream insertion operator. It is linked with the cstdio stream stderr, like cerr. By default, the majority of the systems have their normal error and logging output which is mostly going to the console, where the text messages are displayed, even though this can usually be forwarded. Since, clog is a predefined object of ostream class, it is possible to write characters to it either as formatted data with the help of the insertion operator (<<) or as unformatted data with the help of the write member function.

7 7 Program to demonstrate the usage of cerr and clog objects void test( ) int n = 0; cout << "Enter a number: "<<endl; cin >>n; cerr << "test for cerr" << endl; clog << "test for clog" << endl; int main( ) int i = 0; cout << "Enter a number: "<<endl; cin >> i; cerr << "test for cerr" << endl; clog << "test for clog" << endl; test( ); Enter a number: 3 test for cerr test for clog Enter a number: 2 test for cerr test for clog Program to implement the usage of cerr and clog objects #include <cmath> int number ; cout<<"enter a number : "; cin>>number; if (number<0) cout<<"the value is negative\n"<<endl;

8 8 cout<< "Enter a positive number \n"; exit(0); cout<<"square root of number"<<number<<" is "<<sqrt(number)<<endl; cerr<<"square root of 35 is "<<sqrt(35)<<endl; clog << "The square root of 25 is : "<<sqrt(25)<<endl; return 0; Enter a number : 36 Square root of number 36 is 6 Square root of 35 is The square root of 25 is : 5 Enter a double number: -25 The value is negative Enter a positive number Program to illustrate the usage of clog object class Test int number; Test() clog << "static constructor\n"; ~Test() clog << "static destructor\n"; ; Test t1; // static object clog << "main function\n"; static constructor main function

9 9 static destructor 3.5 Functions of <istream> class Some of the most commonly used functions of <istream> class are get(), getline(), ignore(), peek(), putback() and gcount(). a) get() The get() function is a member function of istream class is mainly used to read a single character from an input device. The different ways of using get() function are: get() function with no arguments get() function with a character argument get() function with two arguments get() function with three arguments get() function with no arguments The get() function with no arguments tries to enter one character from the selected streams including whitespace and it tries to return the character as the value of the function call. When End-Of-File on the stream is encountered, it tries to return EOF. cin.get(); char ch1; ch1=cin.get() Program to implement the usage of get() function with no arguments #include<iostream> int main () char ch1; cout <<"Enter a character : "; ch1 = cin.get(); cout <<"The character that is entered is = "<< ch1<< endl; return 0; Enter a character : Z The character that is entered is = Z

10 10 get() function with a character argument The get() function with a character argument tries to enter the next character from the input stream including whitespace. When End-Of-File (eof) on the stream is encountered, it tries to return false. It tries to returns a reference to the object of istream class for which the get() member function is being invoked. char ch1; cin.get(ch1); Program to implement the use of get() function with a character argument #include<iostream> char ch1; cout <<"Enter a character : "; cin.get(ch1); cout <<"The Character that is entered is "<< ch1; cout<<"\n"; return 0; Enter a character : Z The character that is entered is = Z get() function with two arguments The get() function with two arguments tries to read first n-1 characters one after another into the buffer. The last character is the NULL( \0) character which indicates the end of string and gets attached by the system. cin.get(char*buffer, size_t n); char Name[20]; cin.get(name,6);

11 11 Program to implement the usage of get() function with two arguments int n =0; char Name[20]; cout<<"enter a name : " ; cin.get (Name,6); cout <<"Name that is entered is ; "<< Name <<endl; Enter a name : Sherlock Name that is entered is Sherl get() function with three arguments cin.get( char* buffer, size_t n, char delimeter) In the above syntax: The (n 1) is the highest number of characters that may be read. It also consist of a delimiting character, i.e. char delim. If the delimiter character is met, then the function stops reading the further characters, even though the number (n 1) is not reached. char Buffer [ ]= "Example of getline function in CPP"; char ch1= # ; cin.getline( Buffer, 15,ch1); Program to implement the usage of get() function with three arguments char ch1 = '#'; // # is a delimiting character char Text1[30]; cout<<"\nenter a Text1 : " ; cin.get (Text1,20, ch1 ); cout <<"The text that is written is : "<< Text1 <<endl; Enter a Text1 : this is my first program in cpp on i/o #basics

12 12 The text that is written is : this is my first pr b) getline() The getline() function works like that of get() function, i.e., it tries to add a null character after the line in the character array. It eliminates the delimiter from the stream, but it does not store it in the character array. It is must that the getline() function has to be used with object of istream class and it is mainly useful to read a complete line. The getline() function can have two or three arguments. getline (char* s, streamsize n ); getline (char* s, streamsize n, char delimeter); char Buffer [ ]= "Example of getline function in CPP"; char ch1= # ; cin.getline( Buffer, 20); cin.getline( Buffer, 15,ch1); Program to implement the usage of getline() function char Text[50] ; cout << "Enter Text : "; cin.getline(text,30); cout<<"text that is entered is : "; cout<<text; Enter Text : Hello World Text that is entered is : Hello World c) ignore() The ignore() function reads and it tries to rejects up to n characters or up to the reading of delimiter character or end of file whichever occurs first. The default value of n is 1. cin.ignore (streamsize n, int delimiter) Program to implement the usage of ignore() function int main ()

13 13 char firstname, lastname; cout<<"enter first name and last name: "; firstname = cin.get(); cin.ignore(30,' '); lastname = cin.get(); cout<<"the initial letters are: "<<firstname<<lastname<<endl; return 0; Enter first name and last name: Vivian Richards The initial letters are: VR d) peek() The peek() function returns the next character from an input stream, but it does not take out the character from the stream. cin.peek('h'); e) putback() The putback() function tries to return the formerly read character to the input stream. putback (char c); char ch = D ; cin.peek( F ); cin.putback (ch); Program to implement the usage of peek() and putback() functions char ch1; cout<<"enter a sentence : " ; while (cin.get(ch1)) if (ch1=='a') cin.putback('z'); else cout<<ch1;

14 14 Enter a sentence : This Basket contains 1000 Apples This Basket contains 1000 Zpples f) read() The read() function is a member function of istream class and is mainly used with input streams such as cin.read(). It comes under the category of unformatted Input function. The read() function does enter into the memory some bytes without any formatting. read (char* s, streamsize n); char Text[15]; cin.read(text,15); g) gcount() The gcount() is a member function of istream class which tries to return the number of unformatted characters that is last extracted. streamsize gcount() const; Program to implement the usage of read() and gcount() functions const int length = 100; char Text[length]; cout<<"enter Text :"<<endl; cin.read(text,25); cout<<"the text that is entered is "<<endl; cout.write(text, cin.gcount()); cout<<endl; Enter Text : This is my first program on gcount function The text that is entered is

15 15 This is my first program 4. Functions of <ostream> class Some of the most commonly used functions of <ostream> class are put() and write(). a) put() The put() function is a member function of ostream class. It is mainly used to write a character to output device. The put() function is used with an object of ostream class. put (char c); cout.put(ch1); Program to implement the usage of put() function cout.put('m').put('u').put('m').put('b').put('a').put('i').put(' \n'); char* City = "Cochin"; cout<<city<<endl; cout.put(*city); cout<<"\n"; char city1 [] = "DELHI"; for ( int i = 0; i<5;i++) cout.put(city1[i]); cout.put('\n'); cout.put(70)<<endl; //outputs F character because ASCII value of 70 is F return 0; MUMBAI Cochin C DELHI F b) write() The function write() is a member function of ostream class and is mainly used with output streams such as cout.write(). It comes under the category of unformatted Output function. The

16 write() function output of a number of bytes from the character array in the memory without any formatting. 16 write (const char* s, streamsize n); char Text[30]; cout.write (Text, 30) Program to illustrate the usage of read() and write() functions char sentence [] = "Go to Playground"; cout.write(sentence, 13).put('\n'); char ch1[] = "A"; cout<<"ch1 = "; cout.write(ch1,1)<<endl; char CH1[] = "ABCDEFGHIJO"; cout.write(ch1, 5)<<endl; char Text[30]; cout<< "Enter the Text "; cin.read(text,30); cout.write(text,30)<<endl; return 0; Go to Playgro ch1 = A ABCDE Enter the Text This is a program on read() and write() functions This is a program on read() an 5. Summary C++ includes a hierarchy of classes called as Stream classes that are mainly used to describe various streams to deal with console and disk files. The stream classes are stated in the iostream or iostream.h header file.

17 17 The ios class is the base class for the istream and ostream classes. The istream and ostream classes are in turn base classes for the class iostream, i.e., Input/Output Stream. The ios class offers the basic services that are used by all input and output classes. The istream class declare the input functions such as get(), getline(), read() and it also include overloaded extraction operator (>>). The ostream class declare the input functions such as get(), getline(), read() and it also include overloaded extraction operator (>>). The streambuf class also provides the methods of the class for loading the contents of the buffer, access the contents of the buffer, flush the contents of the buffer, organizing the memory of the buffer. The filebuf class tries to present the necessary and basic operations that are related to files. The strstreambuf class is mainly designed to hold the buffers that are related to memory. C++ language consists of 3 _withassign classes, they are istream_withassign, ostream_withassign and iostream_withassign. The _withassign classes basically consist of assignment operators. The cin is mainly used to get the input from standard input device, such as keyboard. The cout is mainly used to display the output to standard output device, such as monitor or screen. The cerr is mainly used for standard error to display on monitor or screen. The clog is mainly used for buffered error to display on monitor. The cin object object of istream class along with extraction operator ( >>) is mainly used for the input of primary types. It is possible with the cin object to overload the extraction operator (>>) for the user defined types, but it can be used for the class of input object. The cout object of ostream class is used for standard output along with overloaded insertion operator <<. The cout object can be used for user defined data, but it is must that the overloading functions for operator << are to be described by the programmer for the class of the objects being that are dealt with.

18 18 The cerr object is said to be connected to the standard error device, which is a display screen or monitor, but, since, the cerr object is un-buffered, therefore, each stream insertion to cerr causes its output to come into view instantly. The cerr object can also be used in combination with the stream insertion operator. The clog object is said to be connected to the standard error device, which is a display screen, but because, the predefined object clog is buffered, therefore, each insertion to clog might effects its output to be seized in a buffer until the buffer is full or until the buffer is flushed. The get() function is a member function of istream class is mainly used to read a single character from an input device. The get() function with no arguments tries to enter one character from the selected streams including whitespace and it tries to return the character as the value of the function call. The get() function with a character argument tries to enter the next character from the input stream including whitespace. The get() function with two arguments tries to read first n-1 characters one after another into the buffer. When the get() function is used with three arguments, then, if the delimiter character is met, then the function stops reading the further characters, even though the number (n 1) is not reached. The getline() function eliminates the delimiter from the stream, but it does not store it in the character array. The ignore() function reads and it tries to rejects up to n characters or up to the reading of delimiter character or end of file whichever occurs first. The peek() function returns the next character from an input stream, but it does not take out the character from the stream. The putback() function tries to return the formerly read character to the input stream. The read() function does enter into the memory some bytes without any formatting. The gcount() is a member function of istream class which tries to return the number of unformatted characters that is last extracted. The put() function is mainly used to write a character to output device. The write() function output of a number of bytes from the character array in the memory without any formatting.

19 19

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

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

More File Operations. Lecture 17 COP 3014 Spring april 18, 2018

More File Operations. Lecture 17 COP 3014 Spring april 18, 2018 More File Operations Lecture 17 COP 3014 Spring 2018 april 18, 2018 eof() member function A useful member function of the input stream classes is eof() Stands for end of file Returns a bool value, answering

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

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

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

Unit-V File operations

Unit-V File operations Unit-V File operations What is stream? C++ IO are based on streams, which are sequence of bytes flowing in and out of the programs. A C++ stream is a flow of data into or out of a program, such as the

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

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

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

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 7-1 Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Type Conversation / Casting Name Constant - const, #define X When You Mix Apples and Oranges: Type Conversion Operations

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

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

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

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

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

Formatting outputs String data type Interactive inputs File manipulators. Access to a library that defines 3. instead, a library provides input

Formatting outputs String data type Interactive inputs File manipulators. Access to a library that defines 3. instead, a library provides input Input and Output Outline Formatting outputs String data type Interactive inputs File manipulators CS 1410 Comp Sci with C++ Input and Output 1 CS 1410 Comp Sci with C++ Input and Output 2 No I/O is built

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

Characters, c-strings, and the string Class. CS 1: Problem Solving & Program Design Using C++

Characters, c-strings, and the string Class. CS 1: Problem Solving & Program Design Using C++ Characters, c-strings, and the string Class CS 1: Problem Solving & Program Design Using C++ Objectives Perform character checks and conversions Knock down the C-string fundamentals Point at pointers and

More information

C++ Input/Output Chapter 4 Topics

C++ Input/Output Chapter 4 Topics Chapter 4 Topics Chapter 4 Program Input and the Software Design Process Input Statements to Read Values into a Program using >>, and functions get, ignore, getline Prompting for Interactive Input/Output

More information

3. Functions. Modular programming is the dividing of the entire problem into small sub problems that can be solved by writing separate programs.

3. Functions. Modular programming is the dividing of the entire problem into small sub problems that can be solved by writing separate programs. 1 3. Functions 1. What are the merits and demerits of modular programming? Modular programming is the dividing of the entire problem into small sub problems that can be solved by writing separate programs.

More information

String Class in C++ When the above code is compiled and executed, it produces result something as follows: cin and strings

String Class in C++ When the above code is compiled and executed, it produces result something as follows: cin and strings String Class in C++ The standard C++ library provides a string class type that supports all the operations mentioned above, additionally much more functionality. We will study this class in C++ Standard

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

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

UCA31 - PROGRAMMING IN C++ Unit-1 Principal of OOP Type: 75% Theory & 25 % Numerical Question and Answer

UCA31 - PROGRAMMING IN C++ Unit-1 Principal of OOP Type: 75% Theory & 25 % Numerical Question and Answer ACADEMIC YEAR: 2016 2017 REGULATION CBCS - 2012 UCA31 - PROGRAMMING IN C++ Unit-1 Principal of OOP Type: 75% Theory & 25 % Numerical Question and Answer PART A QUESTIONS 1. What are the limitations of

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

Chapte t r r 9

Chapte t r r 9 Chapter 9 Session Objectives Stream Class Stream Class Hierarchy String I/O Character I/O Object I/O File Pointers and their manipulations Error handling in Files Command Line arguments OOPS WITH C++ Sahaj

More information

LECTURE 15. String I/O and cstring library

LECTURE 15. String I/O and cstring library LECTURE 15 String I/O and cstring library RECAP Recall that a C-style string is a character array that ends with the null character. Character literals in single quotes: 'a', '\n', '$ String literals in

More information

Understanding main() function Input/Output Streams

Understanding main() function Input/Output Streams Understanding main() function Input/Output Streams Structure of a program // my first program in C++ #include int main () { cout

More information

Software Design & Programming I

Software Design & Programming I Software Design & Programming I Starting Out with C++ (From Control Structures through Objects) 7th Edition Written by: Tony Gaddis Pearson - Addison Wesley ISBN: 13-978-0-132-57625-3 Chapter 3 Introduction

More information

Fall 2017 CISC/CMPE320 9/27/2017

Fall 2017 CISC/CMPE320 9/27/2017 Notices: CISC/CMPE320 Today File I/O Text, Random and Binary. Assignment 1 due next Friday at 7pm. The rest of the assignments will also be moved ahead a week. Teamwork: Let me know who the team leader

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

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

Object Oriented Pragramming (22316)

Object Oriented Pragramming (22316) Chapter 1 Principles of Object Oriented Programming (14 Marks) Q1. Give Characteristics of object oriented programming? Or Give features of object oriented programming? Ans: 1. Emphasis (focus) is on data

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

Lecture 3 The character, string data Types Files

Lecture 3 The character, string data Types Files Lecture 3 The character, string data Types Files The smallest integral data type Used for single characters: letters, digits, and special symbols Each character is enclosed in single quotes 'A', 'a', '0',

More information

C++ does not, as a part of the language, define how data are sent out and read into the program

C++ does not, as a part of the language, define how data are sent out and read into the program Input and Output C++ does not, as a part of the language, define how data are sent out and read into the program I/O implementation is hardware dependent The input and output (I/O) are handled by the standard

More information

3.1. Chapter 3: Displaying a Prompt. Expressions and Interactivity

3.1. Chapter 3: Displaying a Prompt. Expressions and Interactivity Chapter 3: Expressions and Interactivity 3.1 The cin Object Copyright 2009 Pearson Education, Inc. Copyright 2009 Publishing Pearson as Pearson Education, Addison-Wesley Inc. Publishing as Pearson Addison-Wesley

More information

Object Oriented Programming COP3330 / CGS5409

Object Oriented Programming COP3330 / CGS5409 Object Oriented Programming COP3330 / CGS5409 Dynamic Allocation in Classes Review of CStrings Allocate dynamic space with operator new, which returns address of the allocated item. Store in a pointer:

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

Course "Data Processing" Name: Master-1: Nuclear Energy Session /2018 Examen - Part A Page 1

Course Data Processing Name: Master-1: Nuclear Energy Session /2018 Examen - Part A Page 1 Examen - Part A Page 1 1. mydir directory contains three files: filea.txt fileb.txt filec.txt. How many files will be in the directory after performing the following operations: $ ls filea.txt fileb.txt

More information

Streams. Parsing Input Data. Associating a File Stream with a File. Conceptual Model of a Stream. Parsing. Parsing

Streams. Parsing Input Data. Associating a File Stream with a File. Conceptual Model of a Stream. Parsing. Parsing Input Data 1 Streams 2 Streams Conceptual Model of a Stream Associating a File Stream with a File Basic Stream Input Basic Stream Output Reading Single Characters: get() Skipping and Discarding Characters:

More information

Objectives. In this chapter, you will:

Objectives. In this chapter, you will: Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about

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

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

G52CPP C++ Programming Lecture 14. Dr Jason Atkin

G52CPP C++ Programming Lecture 14. Dr Jason Atkin G52CPP C++ Programming Lecture 14 Dr Jason Atkin 1 Last Lecture Automatically created methods: A default constructor so that objects can be created without defining a constructor A copy constructor used

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

CSC 138 Structured Programming CHAPTER 4: TEXT FILE [PART 1]

CSC 138 Structured Programming CHAPTER 4: TEXT FILE [PART 1] CSC 138 Structured Programming CHAPTER 4: TEXT FILE [PART 1] LEARNING OBJECTIVES Upon completion, you should be able to: o define C++ text files o explain the benefits of using I/O file processing o explain

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

C++ basics Getting started with, and Data Types.

C++ basics Getting started with, and Data Types. C++ basics Getting started with, and Data Types pm_jat@daiict.ac.in Recap Last Lecture We talked about Variables - Variables, their binding to type, storage etc., Categorization based on storage binding

More information

Definition Matching (10 Points)

Definition Matching (10 Points) Name SOLUTION Closed notes and book. If you have any questions ask them. Write clearly and make sure the case of a letter is clear (where applicable) since C++ is case sensitive. There are no syntax errors

More information

Chapter-12 DATA FILE HANDLING

Chapter-12 DATA FILE HANDLING Chapter-12 DATA FILE HANDLING Introduction: A file is a collection of related data stored in a particular area on the disk. Programs can be designed to perform the read and write operations on these files.

More information

Computer Programming : C++

Computer Programming : C++ The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming : C++ Experiment #1 Basics Contents Structure of a program

More information

Chapter 3: Input/Output

Chapter 3: Input/Output Chapter 3: Input/Output I/O: sequence of bytes (stream of bytes) from source to destination Bytes are usually characters, unless program requires other types of information Stream: sequence of characters

More information

Streams in C++ Stream concept. Reference information. Stream type declarations

Streams in C++ Stream concept. Reference information. Stream type declarations Stream concept A stream represent a sequence of bytes arriving, being retrieved, being stored, or being sent, in order. A stream is continuos and offer sequential access to the data. Each byte can be read

More information

Page 1

Page 1 Virtual Functions (introduction) A virtual function is one that does not really exist but it appears real in some parts of the program. Virtual functions are advanced features of the object oriented programming

More information

Today in CS162. External Files. What is an external file? How do we save data in a file? CS162 External Data Files 1

Today in CS162. External Files. What is an external file? How do we save data in a file? CS162 External Data Files 1 Today in CS162 External Files What is an external file? How do we save data in a file? CS162 External Data Files 1 External Files So far, all of our programs have used main memory to temporarily store

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

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

Introduction to Programming using C++

Introduction to Programming using C++ Introduction to Programming using C++ Lecture One: Getting Started Carl Gwilliam gwilliam@hep.ph.liv.ac.uk http://hep.ph.liv.ac.uk/~gwilliam/cppcourse Course Prerequisites What you should already know

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

The C++ Language. Arizona State University 1

The C++ Language. Arizona State University 1 The C++ Language CSE100 Principles of Programming with C++ (based off Chapter 2 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

More information

CS150 Intro to CS I. Fall Fall 2017 CS150 - Intro to CS I 1

CS150 Intro to CS I. Fall Fall 2017 CS150 - Intro to CS I 1 CS150 Intro to CS I Fall 2017 Fall 2017 CS150 - Intro to CS I 1 Character Arrays Reading: pp.554-568 Fall 2017 CS150 - Intro to CS I 2 char Arrays Character arrays can be used as special arrays called

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

by Pearson Education, Inc. All Rights Reserved. 2

by Pearson Education, Inc. All Rights Reserved. 2 Data that is formatted and written to a sequential file as shown in Section 17.4 cannot be modified without the risk of destroying other data in the file. For example, if the name White needs to be changed

More information

KOM3191 Object Oriented Programming Dr Muharrem Mercimek OPERATOR OVERLOADING. KOM3191 Object-Oriented Programming

KOM3191 Object Oriented Programming Dr Muharrem Mercimek OPERATOR OVERLOADING. KOM3191 Object-Oriented Programming KOM3191 Object Oriented Programming Dr Muharrem Mercimek 1 OPERATOR OVERLOADING KOM3191 Object-Oriented Programming KOM3191 Object Oriented Programming Dr Muharrem Mercimek 2 Dynamic Memory Management

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

C++ Programming: From Problem Analysis to Program Design, Fourth Edition. Chapter 5: Control Structures II (Repetition)

C++ Programming: From Problem Analysis to Program Design, Fourth Edition. Chapter 5: Control Structures II (Repetition) C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 5: Control Structures II (Repetition) Objectives In this chapter, you will: Learn about repetition (looping) control structures

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

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

Ch 6-8. C-Strings. April 30, Prof. Young-Tak Kim

Ch 6-8. C-Strings. April 30, Prof. Young-Tak Kim 2014-1 Ch 6-8. C-Strings April 30, 2014 Advanced Networking Technology Lab. (YU-ANTL) Dept. of Information & Comm. Eng, Graduate School, Yeungnam University, KOREA (Tel : +82-53-810-2497; Fax : +82-53-810-4742

More information

3.1. Chapter 3: The cin Object in Program 3-1. Displaying a Prompt 8/23/2014. The cin Object

3.1. Chapter 3: The cin Object in Program 3-1. Displaying a Prompt 8/23/2014. The cin Object Chapter 3: Expressions and Interactivity 3.1 The cin Object The cin Object The cin Object in Program 3-1 Standard input object Like cout, requires iostream file Used to read input from keyboard Information

More information

Chapter 3: Expressions and Interactivity

Chapter 3: Expressions and Interactivity Chapter 3: Expressions and Interactivity 3.1 The cin Object The cin Object Standard input object Like cout, requires iostream file Used to read input from keyboard Information retrieved from cin with >>

More information

C++ For Science and Engineering Lecture 12

C++ For Science and Engineering Lecture 12 C++ For Science and Engineering Lecture 12 John Chrispell Tulane University Monday September 20, 2010 Comparing C-Style strings Note the following listing dosn t do what you probably think it does (assuming

More information

C Style Strings. Lecture 11 COP 3014 Spring March 19, 2018

C Style Strings. Lecture 11 COP 3014 Spring March 19, 2018 C Style Strings Lecture 11 COP 3014 Spring 2018 March 19, 2018 Recap Recall that a C-style string is a character array that ends with the null character Character literals in single quotes a, \n, $ string

More information

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points)

CPE 112 Spring 2015 Exam II (100 pts) March 4, Definition Matching (8 Points) Name Definition Matching (8 Points) 1. (8 pts) Match the words with their definitions. Choose the best definition for each word. Relational Expression Iteration Counter Count-controlled loop Loop Flow

More information

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

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

Outline. 1 Function calls and parameter passing. 2 Pointers, arrays, and references. 5 Declarations, scope, and lifetimes 6 I/O

Outline. 1 Function calls and parameter passing. 2 Pointers, arrays, and references. 5 Declarations, scope, and lifetimes 6 I/O Outline EDAF30 Programming in C++ 2. Introduction. More on function calls and types. Sven Gestegård Robertz Computer Science, LTH 2018 1 Function calls and parameter passing 2 Pointers, arrays, and references

More information

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

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

CPE Summer 2015 Exam I (150 pts) June 18, 2015

CPE Summer 2015 Exam I (150 pts) June 18, 2015 Name Closed notes and book. If you have any questions ask them. Write clearly and make sure the case of a letter is clear (where applicable) since C++ is case sensitive. You can assume that there is one

More information

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable Basic C++ Overview C++ is a version of the older C programming language. This is a language that is used for a wide variety of applications and which has a mature base of compilers and libraries. C++ is

More information

CS 151 Review #3. // More than one variable can be defined // in a statement. Multiple variables are // separated by a comma.

CS 151 Review #3. // More than one variable can be defined // in a statement. Multiple variables are // separated by a comma. REVIEW cout Statement The cout statement invokes an output stream, which is a sequence of characters to be displayed to the screen. cout

More information

Chapter 3: Expressions and Interactivity. Copyright 2012 Pearson Education, Inc. Thursday, October 9, 14

Chapter 3: Expressions and Interactivity. Copyright 2012 Pearson Education, Inc. Thursday, October 9, 14 Chapter 3: Expressions and Interactivity 3.1 The cin Object The cin Object Standard input object Like cout, requires iostream file Used to read input from keyboard Information retrieved from cin with >>

More information

TEST 1 CS 1410 Intro. To Computer Science Name KEY. October 13, 2010 Fall 2010

TEST 1 CS 1410 Intro. To Computer Science Name KEY. October 13, 2010 Fall 2010 TEST 1 CS 1410 Intro. To Computer Science Name KEY October 13, 2010 Fall 2010 Part I: Circle one answer only. (2 points each) 1. The decimal representation of binary number 11011 2 is a) 19 10 b) 29 10

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

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

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p.

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p. Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p. 9 Self-Test Exercises p. 11 History Note p. 12 Programming and

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

C++ files and streams. Lec 28-31

C++ files and streams. Lec 28-31 C++ files and streams Lec 28-31 Introduction So far, we have been using the iostream standard library, which provides cin and cout methods for reading from standard input and writing to standard output

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

Documentation. Programming / Documentation Slide 42

Documentation.   Programming / Documentation Slide 42 Documentation http://www.math.upb.de/~robsy/lehre/programmierkurs2008/ Programming / Documentation Slide 42 Memory Management (I) There are several types of memory which a program can access: Stack Every

More information

CHAPTER 2.1 CONTROL STRUCTURES (SELECTION) Dr. Shady Yehia Elmashad

CHAPTER 2.1 CONTROL STRUCTURES (SELECTION) Dr. Shady Yehia Elmashad CHAPTER 2.1 CONTROL STRUCTURES (SELECTION) Dr. Shady Yehia Elmashad Outline 1. The if Selection Structure 2. The if/else Selection Structure 3. The switch Multiple-Selection Structure 1. The if Selection

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

File Operations. Lecture 16 COP 3014 Spring April 18, 2018

File Operations. Lecture 16 COP 3014 Spring April 18, 2018 File Operations Lecture 16 COP 3014 Spring 2018 April 18, 2018 Input/Ouput to and from files File input and file output is an essential in programming. Most software involves more than keyboard input and

More information

Basic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces

Basic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces Basic memory model Using functions Writing functions Basics Prototypes Parameters Return types Functions and memory Names and namespaces When a program runs it requires main memory (RAM) space for Program

More information

CS242 COMPUTER PROGRAMMING

CS242 COMPUTER PROGRAMMING CS242 COMPUTER PROGRAMMING I.Safa a Alawneh Variables Outline 2 Data Type C++ Built-in Data Types o o o o bool Data Type char Data Type int Data Type Floating-Point Data Types Variable Declaration Initializing

More information