Sie sind auf Seite 1von 22

WWW.VIDYARTHIPLUS.

COM

UNIT III C++ PROGRAMMING ADVANCED FEATURES


Abstract class Exception handling - Standard libraries - Generic Programming - templates class
template - function template STL containers iterators function adaptors allocators Parameterizing the class - File handling concepts.

ABSTRACT CLASS
The purpose of an abstract class (often referred to as an ABC) is to provide an appropriate base class
from which other classes can inherit. Abstract classes cannot be used to instantiate objects and serves
only as an interface. Attempting to instantiate an object of an abstract class causes a compilation error.
Thus, if a subclass of an ABC needs to be instantiated, it has to implement each of the virtual functions,
which means that it supports the interface declared by the ABC. Failure to override a pure virtual
function in a derived class, then attempting to instantiate objects of that class, is a compilation error.
Classes that can be used to instantiate objects are called concrete classes.

EXCEPTION HANDLING
An exception is any unusual event, either erroneous or not, detectable by either hardware or software,
that may require special processing.

WITHOUT EXCEPTION HANDLING

WITH EXCEPTION HANDLING

When an exception occurs, control


goes to the operating system,
where typically
an error message is
displayed
the program is terminated

Programs are allowed to trap


exceptions
There is a possibility to fix the
problem and continuing execution

Exception handling mechanism


To detect and report error
The error handling code performs the following task
1. Find the problem (Hit the exception)
2. Inform that an error has occurred.(Throw the exception)
3. Receive the error information.(Catch the exception)
4. Take corrective actions(Handle the exception) .

Keywords in Exception Handling


1. try
2.throw
3. catch
WWW.VIDYARTHIPLUS.COM

V+ TEAM

WWW.VIDYARTHIPLUS.COM

TRY BLOCK -The keyword try is used to preface a block of statements(surrounded by braces)
which may generate exceptions.

->When an exception is detected, it is thrown using a throw statement in the try block.

CATCH BLOCK - defined by the keyword catch catches the exception thrown by the throw
statement in the try block, and handles it appropriately.

Exception Handling Syntax:


try
//try block
{
.
throw exception;
// Block of statements which
.
// detects and throws an exception
}
catch(type arg) // Catches exception
{
.
.. // Block of statements that
.. // handles the exception
}

EG:
#include <iostream>
WWW.VIDYARTHIPLUS.COM

V+ TEAM

WWW.VIDYARTHIPLUS.COM
int main()
cout << start;
try
{
// start a try block
cout << Inside try block\n;
throw 100;
// throw an error
cout << This will not execute;
}
catch (int i)
{
// catch an error
cout << caught an exception ;
cout << i ;
cout << End;
return 0;
}
}

Exception Types

Synchronous Exception:
Out of rage
Over flow
Asynchronous Exception
-Error that are caused beyond the control of the program
Keyboard interrupts

In C++ only synchronous exception can be handled.

Factors determining Exception

Division by zero
Access to an array outside of its bounds
Running out of memory

Running out of disk space

Need for Exception Handling


Dividing the error handling
Unconditional termination & programmer preferred termination
Separating error reporting and error handling

Object destroy problem


#include<iostream.h>
int main()
{
int i,j;
cout << "Starts here\n";
i=10;
j=0;
WWW.VIDYARTHIPLUS.COM

V+ TEAM

WWW.VIDYARTHIPLUS.COM
if(j==0)
{
cout<<RESULT IS <<i/j;
}
else
return 0;
}
#include<iostream.h>
int main()
{
int i,j;
cout << "Starts here\n";
i=10;
j=0;
try
{
// start a try block
cout << "Inside try block\n";
if(j==0)
{
throw j; // throw an error
cout << "This will not be printed \n";
}
cout<<RESULT IS <<i/j;
}

catch( int a)
{ // catch an error
cout << "The Number Caught is : ";
cout << a << "\n";
}
cout << "Ends here";
return 0;
}

When the program enters the try block it is said to be in the guarded section.
In this program when the value of j is zero an exception is created and thrown.
Note that the statements after throw statement in try block is not executed.
Once the exception is thrown the catch block catches the value (here zero) and handles it.
After that the program continues it normal execution.

Functions Generating Exceptions

C++ allows functions to generate exceptions.


These functions cannot be called as an ordinary function.
Enclose the function call with a try catch block
syntax:
try
{
function(arg);
}
catch(type arg)
{

WWW.VIDYARTHIPLUS.COM

V+ TEAM

WWW.VIDYARTHIPLUS.COM
-----}
#include<iostream.h>
void compute(int a,int b)
{
int c;
if(b==0)
{
throw b;
else
c=a/b;
}
cout<<RESULT OF THE DIVISION<<c;
}

void main()
{
int x,y;
cout<<ENTER TWO NUMBERS;
cin>>x>y;
try
{
compute(x/y); // fun generating exception
}catch(int k)
{
cout<<DIVIDE BY ZERO
EXCEPTION<<endl;
}
}

Throwing Mechanisms

An exception is thrown by using the throw keyword from inside the try block.
A throw expression accepts one parameter, which is passed as an argument to the exception
handler.
EX: throw b;
The throw statement will have the following EG: form
throw (exception)
throw exception
-- throw

Catching Mechanisms

if the data type specified by a catch, matches that of the exception, then catch statement is
executed.
When an exception is caught, arg will receive its value

Multiple Catch Statements

A try can have multiple catches


if there are multiple catches for a try, only one of the matching catch is selected and that
corresponding catch block is executed.

syntax:
try
{
any statements
if (some condition) throw value1;
else if (some other condition) throw value2;
else if (some last condition) throw valueN;
}
catch (type1 name)
WWW.VIDYARTHIPLUS.COM

V+ TEAM

WWW.VIDYARTHIPLUS.COM
{
any statements
}
catch (type2 name)
{
any statements
}
catch (typeN name)
{
any statements
}
eg:
#include<iostream.h>
void multiple_catch(int value)
{
try
{
if (value==0) //throw an int value
throw 1;
else if (value==1) //throw a char
throw a;
else //throw float
throw 1.1;
}
catch(char c)
{
cout<<Character value is thrown <<c;
}
catch(int i)
{
cout<<Integer value is thrown<<i;
}
catch(float f)
{
cout<<Float value is thrown<<f;
}
}
void main()
{
cout<<Main Program<<endl;
multiple_catch(0);
multiple_catch(1);
multiple_catch(5);
}

Rethrowing Exceptions
WWW.VIDYARTHIPLUS.COM

V+ TEAM

WWW.VIDYARTHIPLUS.COM

syntax:
try
{
.
throw a;.
}
catch (char c)
{
throw;
}

//rethrow same exception in

catch block in main()

eg:
#include <iostream.h>
class sam{
into erno;
public:
sam (int errno){
exno=errno;
}
void shoex()
{
cout<<error no:<<exno;
}
};
void ergen(){
try{
sam s1(20);
int c;
cin>>c;
switch (c)
{
case 1:
throw 10;
case 2:
throw a;
case 3:
throw s1;
case 4:
throw welcome;
}
catch (int ie)
{
cout<<ie<<ie;
throw; //rethrowing
}
catch (char ce)
{
cout <<ce<<ce;
WWW.VIDYARTHIPLUS.COM

V+ TEAM

WWW.VIDYARTHIPLUS.COM
throw; //rethrowing
}
}
void main (){
try{
ergen();
throw 10;
}
catch (int)
{
cout <<caught integer;
}
catch(char)
{
cout<<caught char;
}
catch (sam s2){
s2.show x();
}
}

Terminate Function

Use :

Terminate () is the function which calls abort() to exit the program in the event of run time error
related to exceptions
the user can provide his or her own terminate function instead of built-in terminate

Used to close all open files & deallocate resources before quitting the program.
Syntax: set_terminate (myterminate);

Unexpected Function

if a function throws an exception which is not allowed, a function unexpected () is called, which
in turn calls abort.
We can use set_unexpected in a similar to set_terminate
Syntax: set_unexcepted(my unexcepted);
eg:
#include <iostream>
void myunexpected ()
{
cout << "unexpected called\n";
throw 0; // throws int (in exception-specification)
}
void myfunction () throw (int)
{
throw 'x'; // throws char (not in exception-specification)
}
int main (void)
{
WWW.VIDYARTHIPLUS.COM

V+ TEAM

WWW.VIDYARTHIPLUS.COM
set_unexpected (myunexpected);
try {
myfunction();
}
catch (int)
{
cout << "caught int\n";
}
catch (...)
{
cout << "caught some other exception type\n";
}
return 0;
}

Uncaught Exception()
This function returns true if an exception has been thrown but not yet caught.
Once caught, the function returns false.
Syntax: bool uncaught_exceptions.
If (uncaught_exception())
{
//Do not call the function which might throw an exception
}
Otherwise
{
Follow the natural sequence of the destructor Algorithm
}

Generic programming
Generic programming means that you are not writing source code that is compiled as-is but that you write
"templates" of source codes that the compiler in the process of compilation transforms into source codes. The
simplest example for generic programming are container classes like arrays, lists or maps that contain a
collection of other objects. But there's much more to generic programming. In the context of C++ .it means to
write programs that are evaluated at compile time.
A basic example of generic programming are templates of containers: In a statically typed language like C++
you would have to declare separate containers that hold integers, floats, and other types or deal with pointers
to void and therefore losing all type information. Templates which are the C++ way of generic programming
leverage this constraint by letting you define classes where one or more parameters are unspecified at the time
you define the class. When you instance the template later you tell the compiler which type it should use to
create the class out of the template.
Example:

template<typename T>
class MyContainer
{
// Container that deals with an arbitrary type T
};
void main()
{
WWW.VIDYARTHIPLUS.COM

V+ TEAM

WWW.VIDYARTHIPLUS.COM
// Make MyContainer take just ints.
MyContainer<int> intContainer;
}

Templates
A significant benefit of object oriented programming is reusability of
code which eliminates redundant coding.
An important feature of oops called Templates makes this benefit
stronger and provides the greater flexibility to the languages
A template allows the construction of family of functions and classes to perform the same
operation on different types
This provides the generic programming which allows developing the
reusable software component such as classes and function
There are two types of templates
Function templates
Class templates
Terms which means use the same function or class for different purpose without changing their
basic meaning where the function or class should be defined only once
Templates are used to achieve reusability which eliminates redundant code

Class Templates
Class templates are used to create generic class witch support different data types.
Syntax:
template <class T>
class <class_name>
{
Member;
Member function;
};
Example:
#include<iostream.h>
#include<conio.h>
template <class T>
class complex
{
T real ,image;
public:
void getdata()
{
cout<<"\n Enter the complex values";
cin>>real>>image;
}
void putdata()
{
if(image>0)
cout<<real<<"+"<<image<<"i";
WWW.VIDYARTHIPLUS.COM

V+ TEAM

WWW.VIDYARTHIPLUS.COM
else
cout<<real<<image<"i";
}
};
void main()
{
clrscr();
complex <int> obj1;
obj1.getdata();
obj1.putdata();
complex <float> obj2;
obj2.getdata();
obj2.putdata();
getch();
}

FRIEND OF CLASS TEMPLTAES


A friend of a class template can be one of the following:
Class template
Function template
Non-template function
Non-template class
A specialization of class template
A specialization of function template

Function Template
The template declared for function are function template
Function templates are generic function, which work for any data that is passed to them .
The data type is not specified while declaring the function
It performs appropriate operation depending on the data type we passed to them .
Syntax:
Template<typename T ,.>
Return Type Function-name(argument)
{
Function body
}
eg:
Template < class T>
Void generic Bubblesort(T Temp GenericArray[]) // template function 1
{
For( int i=0;i<5; i++)
{
For( int j=i+1;j<5;j++)
{
If(TempGenericArray[i]<TempGenericArray[j])
{
WWW.VIDYARTHIPLUS.COM

V+ TEAM

WWW.VIDYARTHIPLUS.COM
int temp=TempGenericArray[i];
TempGenericArray[i]=TempGenericArray[j];
TempGenericArray[j]=temp;
}
}
}
}
Template <class T>
Void Generic Display(T TempGenericArray[])
// template function2
{
Cout<<\n;
For(int i=0;i<5;i++)
{
Cout<<TempGenericArray[i]<<\t;
}}
Void main()
{
int Array1[]={1,4,6,2,6}
GenericBubbleSort(Array 1);
//calling function template 1
GenericDisplay(Array2);
// calling function template 2
Char Array2[]=sdfla;
GenaricBubbleSort(Array2)
//calling function template 1
Generic Display(Array 2);
Foat Array3[]={ 7.0,9.4,5.2,2.5,0.5);
GenericBubble Sort (Array 3); // calling function template 1
GenericBubbleSort( Array3 ); // calling function template 2
}
Sample output:
6
6
4
2
1
S
k
f
d
a
9.4
7
5.2
2.5
0.5

Function templates with multiple arguments


Function templates can have different data type to represent the parameters.
Syntax:
template <class T1,class T2>
return_type function_name(arguments)
{
<function body>
}
Example:
#include<iostream.h>
#include<conio.h>
template <class T1,class T2>
void display(T1 a,T2 b)
{
cout<<a<<"\n"<<b<<"\n";
}
WWW.VIDYARTHIPLUS.COM

V+ TEAM

WWW.VIDYARTHIPLUS.COM
void main()
{
clrscr();
//void display(T1,T2);
display("sample","program");
display(10,20);
display(7.5,2);
display(10.75,10.256);
getch()
}

TEMPLATE COMPILATION MODELS


Standard C++ defines two models for compiling template code. In each of these models, class
declarations and function declarations are placed in header files and functions and member from the
source files are made available to the compiler. the models the definitions from the source files are
made available to the compiler. The models are
Inclusion compilation model
Separate compilation model
Inclusion compilation model
It is possible to compile the template spread across multiple files by having the copy of the template
text in all the files . This model is known as the inclusion compilation model.
Separate compilation model
It is possible to compile template separately and then use them by providing their prototype in
other files .this model is known as the separate compilation model.

Standard library functions


STREAMS AND FORMATTED I/O :

A stream is a sequence of bytes (or) conceptually pipe like constructs used for providing I/O.
Streams provide consistent interface for providing independence from having different
operations for different IO devices.
The source stream that provides data to the program is called the input stream.
The destination stream that receives output from the program is called the output stream.

(refer diagram in notebook)

C++ STREAM CLASSES:


(Refer diagram in notebook)
Ios :

it is the base class for istream and ostream.


It is declared as the virtual base class.
It provides the basic support for formatted and unformatted I/O operations.

Istream:
WWW.VIDYARTHIPLUS.COM

V+ TEAM

WWW.VIDYARTHIPLUS.COM

Provides facilities for formatted and unformatted input operations.


Functions such as getc(),getline(),read() are declared.
Overloaded extraction operator (>>)

Ostream:

Provides the facilities for formatted and unformatted output operations.


Putc() and write() functions are declared.
Overloaded insertion operator (<<)

Streambuf:

It is used to access streams using lower level functions.


Provides an interface to physical devices through buffers.
Acts as a base class for filebuf class.

Iostream:

Provides facilities for handling both input and output streams.


Inherits the properties of ios, istream and ostream through multiple inheritance.

UNFORMATTED I/O OPERATIONS:


1. Overloaded operators >> and << :

The >> operator is overloaded in the istream.


The << operator is overloaded in the ostream.
cin>>variable 1>>.>>variable n ;
the input data are separated by white spaces and should match the type of
variable in cin .

cout<<variable 1<<.<<variable n;
this statement is used for displaying data on the screen.

EXAMPLE :
#include<iostream.h>
void main()
{
int a;
cout<<Enter a variable;
cin>>a;
cout<<The value of a is<<a;
}

Putc() and getc() functions :

getc() and putc() are used for reading and writing to the streams.
The getc() function has two different versions : 1. Void get(char)

WWW.VIDYARTHIPLUS.COM

2. char get(void)
V+ TEAM

WWW.VIDYARTHIPLUS.COM

The put() function is used to display the data.


Get() reads a character at a time from the input stream and put() writes a character at a
time to the output stream.

Example :
#include<iostream.h>
#include<conio.h>
Void main ()
{
Int count=0;
Char c;
cout<<Enter a text;
cin.get(c);
while(c!=\n)
{
Cout.put(c);
Count++;
Cin.get(c);
}
Cout<<\n Number of characters = <<count;
}

Getline ,read and write functions :

These functions are used for reading and writing strings.


The prototypes for these three functions are :
o
o
o

cin.getline(string variable , int size);


cin.read(string variable, int size);
cin.write(string variable,int size);

the difference between getline() and read() is that : getline() terminates when a new line is
entered but read() does not stop when a new line is encountered.
read() stops only when end of file (ctrl + z ) is encountered .
The getline() also stops reading from input if end of file is specified.

Example:
#include<iostream.h>
#include<conio.h>
void main()
{
char msg[100];
Cin.getline(msg,100);
Cout.write(msg,5);
Cin.read(msg,10);
WWW.VIDYARTHIPLUS.COM

V+ TEAM

WWW.VIDYARTHIPLUS.COM
Cout.write(msg,5);
}

Output:
Object
Objec

getline()

Object
( ctrl + z )
objec

read()

FORMATTED I/O OPERATIONS :


Built-in ios functions :
1.width() :

- it specifies the width for display.


-it is used in aligning vertical columns.
2.precision() : -it specifies the precision of the floating point number.
-default precision is six digits after the decimal point.
3.fill() :
- specifies the character for filling up the unused portion of field.
-it is used with width() .
-The function specifies format flags that control output display like left (or) riight or
right justification , padding , scientific notation , displaying base number.
5. unsetf():
-It provides undo operation for the above mentioned operations.

4.setf() :

Example :
#include<iostream.h>
#include<conio.h>
Void main ()
{
Int n;
Cout.fill(*);
Cout.precision(3);
For(n=1;n<=b;n++)
{
Cout.width(5);
Cout<<n;
Cout.width(10);
Cout<<1.0/float(n)<<\n;
If(n>3)
Cout.fill(.);
}
WWW.VIDYARTHIPLUS.COM

V+ TEAM

WWW.VIDYARTHIPLUS.COM
Cout.fill(#);
Cout.width(15);
Cout<<12.345678;
}

Here , width() is used for right justification.


To get left justification , and also to get scientific notations for finding floating point variables , we
should use the setf() .

MANIPULATORS :
Manipulators are special functions for formatting.
The choice between manipulators and ios functions to solve formatting problems sometimes depends
on the preference of the user.

Manipulators :
setw()
setprecison()
setfill()
setiosflags()
resetiosflags()

ios functions :
width()
precision()
fill()
setf()
unsetf()

program
#include<iostream.h>
#include<iomanip>
int main()
(
cout<<setw(15)<<setiosflags(ios::left)<<setiosflags(ios::fixed)<<setprecision(2)<<setiosflags(ios::showpoi
nt);
cout<<"Roll Number"<<setw(15)<<"Name"<<setw(10)<<setprecision(2)<<"Marks"<<endl;
cout<<setw(15)<<1<<setw(15)<<"Lara"<<setw(10)<<setprecision(2)<<355.50<<endl;
cout<<setw(15)<<2<<setw(15)<<"Beckham"<<setw(10)<<setprecision(2)<<275.00<<endl;
cout<<setw(15)<<3<<setw(15)<<"Steffi"<<setw(10)<<setprecision(2)<<290.75<<endl;
cout<<setw(15)<<4<<setw(15)<<"Jaspal"<<setw(10)<<setprecision(2)<<295.00<<endl;
cout<<setw(15)<<5<<setw(15)<<"Parker"<<setw(10)<<setprecision(2)<<200.60<<endl;
}

Characteristics of manipulators:

Writing our own manipulators is possible.


Manipulators are easy to write and produce more readable codes and make the program short.
They need iostream.h and iomanip.h files

WWW.VIDYARTHIPLUS.COM

V+ TEAM

WWW.VIDYARTHIPLUS.COM

When a manipulator does not take any arguments , it is passed without the () parenthesis.
Some manipulators are needed in pairs to produce the toggle effect.
They are non-member-functions.

Characteristics of ios functions:

they are single and cannot be combined to have multiple effects.


They need iostream.h file
ios functions are member functions.
The functions do not return the previous status.

FILE HANDLING
INTRODUCTION:
OS is the primary interface between the user and the computer. Device driver is a small program that
comes with every device IO operations are performed with the help of the OS and the device driver.
A C++ program does not directly request to the OS. It invokes a function from a standard library that
comes with a C++ compiler , when it is installed.

Text and Binary Files :


Text stream:
-deals with information which is in ASCII form.
-if <enter> key is pressed, Carriage return and Line Feed characters are inserted. This is known as
conversion. The text stream files can be opened by any editor.Text files are more general.

Binary streams:
-binary values are inserted
- no conversion takes place.
The binary stream files are restricted to the application that creates the file. Binary files are not flexible.
Dealing With Text Files
Defining Files
ifstream < filename> - read only file
ofstream <filename> - output /write only file
fstream <file name > - both input/read and output /write file.

Manipulating Files
Opening Files :
-files can be opened using two methods
(i) using constructors
(ii) using open functions
Ifstream DisplayFile ( Fewlines.dat); (using constructors)
-it is an ios::in (input mode).
-for output mode replace ifstream by ofstream.
-in the above example fewlines is a physical file name. Displayfile is a logical file name.
-the logical files will vanish when the program is over, but physical files will be available in the
OS.
WWW.VIDYARTHIPLUS.COM

V+ TEAM

WWW.VIDYARTHIPLUS.COM

Displayfile.open(fewlines.dat);

(using open function)

Reading from and writing to files


-use of overloaded << and>> operators are used to read from and write to a file.
Closing Files
-close () - to close a file
-the allocated files are deallocated and flushed off when close () is invoked
Using Text Files
#include<iostream>
#include<fstream>
#include<string>
int main()
{
string inputline,outputline;
ofstram entryfile("fewlines.dat")
cout<<"input:"<<endl;
while(true)
{
cin>>inputline;
if(inputline =="end")break;
entryfile.close();
cout<<"output:"<<endl;
ifstream displayfile.eof())
{
displayfile>>outputline;
cout<<outputline<<"\n";
}
displatfile.close();
return o;
}
Using get () and put ()
#include<iostream>
#include<fstream>
#include<string>
int main()
{
char ch;
ofstream entryfile("fewlines.dat");
while(true)
{
cin.get(ch);
if(ch=='$') break;
entryfile<<ch;
WWW.VIDYARTHIPLUS.COM

V+ TEAM

WWW.VIDYARTHIPLUS.COM
}
entryfile.close();
ifstream displayfile("fewlines.dat");
while(!displayfile.eof())
{
displayfile.unsetf(ios::skipws);
displayfile>>ch;
cout<<ch;
}
displayfile.close();
return 0;
}

Dealing with binary files


Opening a binary file :
Open using a constructor with two arguments :
-name of the file
- file mode
Ofstream Filename;
filename .open (file.dat, ios::out |ios::binary|ios::trunc);
OR
ifstream filename (file.dat, ios::in|ios::binary);
The first method uses a open().
The second method uses a constructor. This is used by most of the users.
Writing a file :
ofstream file_name(file_dat,ios::out|ios::binary|ios::trunc);
Or
ifstream file_name;
file_name.open(file.dat,ios::in|ios::binary);
pipe(i) is used to add multiple modes.
Reading from and Writing To multiple files :
object_file.write((char*)&<the object>,sizeof(<object>));
-this is for writing into the file.
object_file.read((char*)&<the object>,sizeof(<object>));
-this is for reading from the file.
The read() and write() functions are performed object wise and not element wise.
The complete file can be read and written using these single statements.
Closing Binary Files :
WWW.VIDYARTHIPLUS.COM

V+ TEAM

WWW.VIDYARTHIPLUS.COM
file_name.close();
or
file_object.close();
-it deallocates the files and flushes the buffer.
Using Binary Files :
-fail() and eof() are used.
Program pg 567

RANDOM ACCESS :
In C++ , there are two types of file pointers to access a file in a random manner.
For a file in the read mode seekg (pointer for reading or getting)
For a file in the write mode seekp(pointer for wrioting or putting)
Using these , it is possible to search any record of any file by skipping the other records inbetween.
seekg() and seekp() :
seekg() to move get or read pointer of file.
It takes two arguments , (i) number of bytes to skip (ii) from where to skip
seekp() to move put and write pointers.
tellg() and tellp() :
these pointers tell us where the read and write pointers of a file are pointing to.
tellg() tells us where the get pointer is pointing to.
tellp() tells us where the put pointer is pointing to.
Example:
#include"stdafx.h"
#include<iostream>
#include<fstream>
struct record
{
char code[6];
char name[20];
int i;
}r;
int main()
{
std::fstream file("Temp.dat",std::ios::trunc|std::ios::in|std::ios::out|std::ios::binary);
if(!file)
{
std::cout<<"unable to open file";
exit(0);
}
std::cout<<"enter character code, name and an int\n";
std::cin.getline(r.code,6);
std::cin.getline(r.name,20);
WWW.VIDYARTHIPLUS.COM

V+ TEAM

WWW.VIDYARTHIPLUS.COM
std::cin>>r.i;
file.write((char *)&r,sizeof(r));
std::cout<<"\n\n"<<file.tellg()<<'\n'<<file.tellp();
file.seekg(3);
std::cout<<"\n\n"<<file.tellg()<<'\n'<<file.tellp();
file.seekp(5);
std::cout<<"\n\n"<<file.tellg()<<'\n'<<file.tellp();
}

WWW.VIDYARTHIPLUS.COM

V+ TEAM

Das könnte Ihnen auch gefallen