Your Federal Quarterly Tax Payments are due April 15th Get Help Now >>

chapter 7 new by HC12080822249

VIEWS: 0 PAGES: 23

									                                 Chapter 7

    Basic Function of I/O System Basics and
                           File Processing
7.1 New term
     Concept of stream and stream classes’ to implement the I/O operations
      using console.
     The data is stored on the machines in the form of files.
     A file is a collection of related data having details of the particular task.
     Programs can be written to read and write data on to these files.
     Manipulation i.e. addition and deletion of data is also possible on these
      files.
     Files are of data file processing and binary file processing.
I/O system Basics
     We use console input output to control the way the output is printed.
     C++ uses stream and stream classes to implement the operations.
7.1.1 C++ stream
     A stream is a sequence of bytes.
     It acts as a source or an destination.
     The source is from where the input is taken and the destination is where we
      print the output.
     The source is also known as an input stream.
     The destination is known as an output stream.
     C++ contains many pre-defined streams which automatically opens when a
      program is executed.
     We know the cin and the cout streams.
                                     Input Stream
            Input Device



                                                                Program



         Output Device
                                      Output Stream
7.1.2 C++ Stream Classes
       C++ has many classes that define various streams.
       Ios is the base class fot istream and ostream.
       The class ios is declared as virtual.

                                          ios


               istream             streambuf              ostream
    input                                                              output

                                    iostream



      istream_withassi       iostream_withassig         ostream_withassig
      gn                     n                          n
The different stream classes for console operations are
ios
       General input output stream class.
       Contains basic facilities that are used for other input and output classes.
       Contains pointer to the buffer object.
       Declares constants and functions that are necessary for handling formatted
        input and output data.
istream
       This is an input stream.
       Inherits the properties of ios.
       Declares input functions as get( ) , getline( ) and read( ).




             Basic Function of I/O System Basics and File Processing              119
     Contains overloaded extraction operator >>.
ostream
     This is an output stream.
     Inherits the properties of ios.
     Declares output functions put( ) and write( ).
     Contains the overloaded operator <<.
iostream
     This is an input and output stream.
     Inherits the properties of ios, istream and ostream .
     Uses multiple inheritance.
     Contains all input and output functions.
streambuf
     Provides interface to physical devices through buffer.
     This is an base class for filebuf class used ios files.
7.2 Unformatted I/O operations
     cin and cout are used to input and output the data.
     This is possible due to overloading of >> and <<.
     The >> operator is overloaded in the istream.
     The << operator is overloaded in the ostream.
     To read the data from the keyboard we use cin >> var1 >> var2.
     To display the data we use cout << var1<< var2.
put( ) and get( ) functions
     Used to handle single character input and output operations.
     There are two types of get( )functions.
     The get(char*) assigns the input character to its argument.
     The get(void) returns the input character.
     The get( ) function can fetch blank space , tab and a new line character.
     It is used as cin.get( c); , where c is a character data type declared.
     The put is used as cout.put( c);
getline( ) and write( ) Functions




120                    Object Oriented Programming C++
   The getline( ) function reads a whole line of text ending with a newline
    character.
   The function can called using an cin object as
    cin. getline( line, size);
   The line will accept the complete sentence ending with a newline character,
   which is read but not saved.
   Example as
    char name[20];
    cin.getline(name,20);
   Reads a line of character in the variable name.
   This is usually written as cin >> name.
   The write( ) function displays the entire line of text inputted using getline( )
    function.
   The function is called using an cout object.
    cout.write(line , size);
   The first argument represents the variable to be displayed, which holds the
    value.
   The second argument displays the size of the inputted text.
7.2.1 FORMATTED CONSOLE I/O OPERATIONS
   These functions include ios class functions and flags.
    width( )      To specify the required size for displaying the output.
    precision( ) Specify the number of digits after the decimal in the float
                  value
    fill( )       Specifies the character that is used to fill the unused area of a
                  field.
    setf( )       specifies left justification and right justification on format
                  flags.
    unsetf( )     To clear the flags specified.
   The width( ) is used as
    cout.width(w) ;




         Basic Function of I/O System Basics and File Processing                   121
Example
      cout.width(6) ;
      cout << 1123 ;
      cout.width(4) ;
      cout << 45 ;
The output is
            1           1      2    3           4    5
      The output is printed as right justified in the field.

     The fill( ) is used to filll the extra space with the character we want.
             cout.fill(ch) ;
Example
      Cout.fill( # );
      Cout.width( 6);
      Cout << 123;
The output is
#     #      #                1         2   3
     To set flags for justification we use
              cout.setf(arg1,arg2)
     The arg1 is the flag field and the arg2 is the bit field.
     For the particular fag the bitfield are.
                        arg1                        arg2
      left-justified ios::left                      ios::adjustfield
      right justified ios::right                    ios::adjustfield
      padding               ios::internal           ios::adjustfield
     Manipulators are special functions that can be included to alter format
      parameters of a stream.
     To access these manipulators file iomanip.h should be included in the
      program.
     Manipulators have equivalent ios functions also
      Manipulators                                         ios
      setw( )                                              width( )
      setprecision( )                                      precision( )
      setfill( )                                           fill( )




122                           Object Oriented Programming C++
        setiosflags( )                                               setf( )
        resetiosflags( )                                             unsetf( )
       The setw( ) used as
              setw( int w) ;
Example
    cout << setw(6) << 9876 ;
       The output can be left justified as
        cout << setw( 6 ) <<setiosflags ( ios : : left) << 9876 ;

PROGRAM 7.1
Write a program using I/O maipulators for filling & padding using function fill() &
width( ) for following output.
1----- 1
2----- 4
3----- 9
4-----16
5-----25
6-----36
         #include<iostream.h>
         #include<conio.h>
         #include<iomanip.h>
         void main()
         {
          clrscr();
          for(int i=1;i<=6;i++)
          {
                   cout << setfill('-') << setw(6) << setiosflags (ios::left) << i ;
                  cout <<setw(2)<<setiosflags(ios::right)<<setfill(' ')<<i*i<<endl;
          }
          getch();
         }
PROGRAM 7.2
Write a program to read a list containing item_name, item_code, and cost
interactively and produce a three column output as shown below.
NAME                CODE                       COST
Turbo C++                  1001                             250.95
C primer                    905                              95.70
 ….                          …                                …




             Basic Function of I/O System Basics and File Processing                   123
    Note: The name & code are left-justified and cost is right-justified with a
precision of two digits. Trailing zeros are shown
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class item
{
 char item_name[15];
 int item_code;
 float cost;
 public:
 void accept()
 {
           cout<<endl<<"Enter name of the item:";
           cin>>item_name;
           cout<<endl<<"Enter item code of "<<item_name<<":";
           cin>>item_code;
           cout<<endl<<"Enter cost of "<<item_name<<":";
           cin>>cost;
 }
 void display()
 {
           cout<<endl;
           cout<<setw(12)<<setiosflags(ios::left)<<item_name;
           cout<<setw(7)<<item_code;
           cout<<setw(10)<<setiosflags(ios::right) ;
           cout <<setiosflags(ios::showpoint)<<setprecision(2)<<cost;
 }
};
void main()
{
 int i,x,count=0;
 item *p[100];
 clrscr();
 do
 {
  cout<<endl<<"\tMenu";
  cout<<endl<<"1.Insert item in list"<<endl<<"2.View List"<<endl<<"3.Exit";
  cout<<endl<<"Enter your choice";
  cin>>i;
  switch(i)




124                        Object Oriented Programming C++
 {
  case 1:
            if(count>99)
            {
             cout<<"List is full";
             break;
            }
            else
            {
             p[count]=new item;
             p[count]->accept();
             count++;
             break;
            }
  case 2:
            cout<<endl<<setw(12)<<setiosflags(ios::left)<<"NAME";
            cout<<setw(7)<<"CODE";
            cout<<setw(10)<<setiosflags(ios::right)<<"COST";
            for(x=0;x<count;x++)
            {
             p[x]->display();
            }
            break;
  case 3:
             cout<<"Press any key........................";
             break;
            default:
            cout<<"Invalid option entered";
  }
 }while(i!=3);
 getch();
}

PROGRAM 7.3
Write a program to create a user defined manipulator.
        #include<iostream.h>
        #include<conio.h>
        #include<iomanip.h>
        ostream &form(ostream &output)
        {
                output.setf(ios::showpoint);




               Basic Function of I/O System Basics and File Processing   125
                output.setf(ios::showpos);
                output.fill('*');
                output.precision(2);
                output.setf(ios::fixed);
                output.setf(ios::internal);
                output.width(10);
                return(output);
        }
        void main()
        {
         clrscr();
         cout<<form<<7864.5;
         getch();
        }

PROGRAM 7.4
Write a program using manipulators to display output as given below
       Sr. No. Item                     Unit Price          Quantity         Amount
          1      Potato chips              10                  1               10
          2      Chocolate candy           02                 10                20
          3      Cold drink                10                   5               50
          4      Cake                      50                   1               50
       ---------------------------------------------------------------------------------
        #include<iostream.h>
        #include<conio.h>
        #include<iomanip.h>
        ostream &srno(ostream &output)
        {
                output.width(6);
                output.setf(ios::right);
                return(output);
        }
        ostream &item(ostream &output)
        {
                output.width(17);
                output.setf(ios::left);
                return(output);
        }
        ostream &price(ostream &output)
        {
                output.width(6);




126                        Object Oriented Programming C++
             output.setf(ios::right);
             return(output);
     }
     ostream &quantity(ostream &output)
     {
               output.width(10);
               output.setf(ios::right);
               return(output);
     }
     ostream &amt(ostream &output)
     {
               output.width(10);
               output.setf(ios::right);
               return(output);
     }
     void main()
     {
      clrscr();
              cout<<setw(5)<<setiosflags(ios::left)<<"Sr. No." ;
              cout <<setw(17)<<"Item"<<setw(10)<<"Unit Price" ;
              cout<<setw(10)<<setiosflags(ios::right)<<"Quantitiy" ;
              cout<<setw(7)<<setiosflags(ios::right)<<"Amount"<<endl;
              cout<<srno<<"1 "<<item<<" Potato chips" ;
              cout<<price<<"10"<<quantity<<"1"<<amt<<"10"<<endl;
              cout<<srno<<"2 "<<item<<" Chocolate candy" ;
              cout<<price<<"2"<<quantity<<"10"<<amt<<"20"<<endl;
              cout<<srno<<"3 "<<item<<" Cold drink" ;
              cout<<price<<"10"<<quantity<<"5"<<amt<<"50"<<endl;
              cout<<srno<<"4 "<<item<<" Cake" ;
              cout<<price<<"5"<<quantity<<"1"<<amt<<"50"<<endl;
      getch();
     }

7.2.2 Data file processing
    File is a collection of data or a set of characters or may be text or a
     program.
    File system is divided into sequential file and random access file.
    The sequential files are easy to create.




         Basic Function of I/O System Basics and File Processing               127
        The data or text will be stored or read back sequentially in random access
         files.
        In random access files can be accessed and processed randomly.
7.3 Opening and closing of files
        The header file fstream.h supports the input/output stream and for
         important features such as classes, derived class, fun overloading virtual
         function and multiple inheritance.
        The following methods are used in c++ to read and write file
    Ifstream: to read a stream of object from a specific file.
      Ofstream: to write a stream of object.
    Fstream: both to read and write a stream of a file.
        The header file fstream.h is a new class which consists of basic file routine
         and functions.
        The fstream, ifstream and ofstream are called as derived class as these
         class objects are already defined in the basic input and output class namely
         <ofstream .h>
7.3.1 Opening a file
The open( ) function
        The member function open ( ) is used to create a file pointer for opening a
         file in the disk.
        Open is used to open multiple files that use same stream object .
The syntax is
                  file –stream-class stream object;
                  stream-object.open(“filename”);
    Example
                  ofstream outfile;
                  outfile.open(“trial1”);
        The following streams are used to open a file using cons tructor.
        Ifstream: the header fstream.h is a derived class from the base class of
         istream and is used to read a stream of objects from a file.
                   #include <fstream.h>




128                          Object Oriented Programming C++
                 void main( )
                 {
                    ifstream infile ;
                     infile open ( “data file”) ;
                  }

           Ofstream: the header file ofstream .h is derived from base class of
            ostream and is used to write a stream of objects in a file.
                  #include < fstream.h>
                  void main ( )
                  {
                    ofstream infile ;
                     infile open ( “data file”);
                   }
           Fstream: The header file fstream.h is derived from the base class of
            iostream is used for both recording and writing a stream of objects on a
            file. The include <fstream.h> automatically includes iostream.h
                   #include <fstream.h>
                   void main ( )
                 { fstream infile ;
                    infile open ( “data file” , ios in // ios :: out);
                  }
         When a file is opened for both reading and writing, the i/o stream keep
            track of two file pointers one for input and other for output.
void ifstream :: open (const char*fname, int m= ios ::intint port= filebuf ::
openport)
void ofstream::open( const char*fname ,int m=cos :: out, int port =
filebuf:: openport)
void fstream :: open ( const char *fname,int m, int port = filebuf ::openport);

    Note:      For istream (input), default mode is ios :: iu;for ofstream
    instance, the default mode is ios:: out for fstream , there is no default mode.

    ios ::in -> open a file for reading
    Ios :: out-> open a file for writing
    Ios:: app->append at the end of a file
    Ios:: ate -> seek to the end of a file upon opening instead of beginning




            Basic Function of I/O System Basics and File Processing               129
    Ios::trune -> delete a file if it is exits and recreate it
    Ios::nocreate -> open a file if a file does not exist
    Ios::replace -> open a file if does exist
    Ios:: binary ->Open a file for binary mode ;default is lixt.

The default values are
                             0     default
                             1     read only file
                             2     hidden file
                             4    system file
                             8    archive file

put( ) and get( ) functions
         The put( ) function writes a single character to the associated stream.
         Put( ) function is known as the output pointer as it prints the data in to
          the file.
         Put( ) is used for wrting data to the specified file location .
         The function get( ) reads a single character from the associated stream .
         The get( ) function is known as the input pointer as it takes the input
          from the file and displays it on to the screen .
         The data is written to the file using put ( ) function using a for loop, for
          character by character writing of text .
         The get( ) writes the output on to the screen character by character until
          end of file is encountered .
7.4 Functions for file pointer manipulation
      seekg( )       Moves get( ) pointer to the specified location.
      seekp( )       Moves put( ) ointer to the specified location .
      tellg( )       Gives the current position to the get pointer .
      tellp( )       Gives the current position to the put pointer .

The seekg( ) and seep( ) functions are used with two arguments
              seekg( offset , reposition);
              seekp( offset , reposition);
      The offset represents nnumber of bytes the file pointer has to move
       depending on the reposition.
      The reposition takes the different constants.




130                      Object Oriented Programming C++
       ios::beg                  Start of file.
       ios::cur                  Current position of the pointer .
       ios::end                  End of file .

7.4.1 Closing a file
      The member function close( ) is used to close a file which has been opened
       for file processing such as to read , to write and for both to read and write.
      The close( ) member function is called automatically by the destructor
       functions.
      One may call this member function to close a file explicitly.
      The close member function will not contain any arguments.
The general syntax is
       # include < fstream.h >
       void main ( )
       {
               fstream infile ;
               infile : open ( “data file”,os ::in// ios ::out);
               infile close ( ) ;
       };

PROGRAM 7.5
WAP to write a set of lines to a user-defined file.
       #include <iostream.h>
       #include <fstream.h>
       void main()
       {
               ofstream outfile;
               char fname[10];
               cout<<"Enter file name";
               cin>>fname;
               outfile.open(fname);
               outfile<<"This is a sample program";
               outfile.close();
       }

PROGRAM 7.6
WAP to read a set of lines from the keyboard and store it on a specified file.
       #include <iostream.h>
       #include <fstream.h>




           Basic Function of I/O System Basics and File Processing                 131
      #define MAX 2000;
      void main()
      {
              ofstream outfile;
              int i;
              char fname[10], line[MAX];
              cout<<"Enter file name";
              cin>>fname;
              outfile.open(fname);
              cout<<"Enter a set of lines @";
              cin.get(line, 'e');
              cout<<"given input";
              cout<<line;
              cout<<"store to file";
              outfile<<line;
              outfile.close();
      }

PROGRAM 7.7
WAP to read a text file and its contents on the screen.
      #include <iostream.h>
      #include <fstream.h>
      #include <iomanip.h>
      #include <stdlib.h>
      void main()
      {
               ifstream infile;
               int i;
               char fname1[10], ch;
               cout<<"Enter file name";
               cin>>fname1;
               nfile.open(fname1);
               if(infile.fail())
               {
                        cerr<<"No file exists";
                        exit(1);
               }
      while(!infile.eof())
      {
               ch = (char)infile.get();
               cout<<put(ch);




132                       Object Oriented Programming C++
      }
      infile.close();

PROGRAM 7.8
WAP to Copy the contents of one text file to another.
      #include <iostream.h>
      #include <fstream.h>
      #include <iomanip.h>
      #include <stdlib.h>
      void main()
      {
              ifstream infile;
              ofstream outfile;
              int i;
              char fname1[10], fname2[10], ch;
              cout<<"Enter file name to be copied";
              cin>>fname1;
              cout<<"New file name";
              cin>>fname2;
              infile.open(fname1);
              if(infile.fail())
              {
                       cerr<<"No file exists";
                       exit(1);
              }
              outfile.open(fname2);
              if(outfile.fail())
              {
                       cerr<<"Unable to create";
                       exit(1);
              }
              while(!infile.eof())
              {
                       ch = (char)infile.get();
                       outfile.put(ch);
              }
              infile.close();
              outfile.close();
      }




           Basic Function of I/O System Basics and File Processing   133
PROGRAM 7.9
WAP to convert lower case characters to uppercase character of a text file.
      #include <iostream.h>
      #include <fstream.h>
      #include <iomanip.h>
      #include <stdlib.h>
      #include <ctype.h>
      void main()
      {
              ifstream infile;
              ofstream outfile;
              int i;
              char fname1[10], fname2[10], ch, upperch;
              cout<<"Enter file name to be copied";
              cin>>fname1;
              cout<<"New file name";
              cin>>fname2;
              infile.open(fname1);
              if(infile.fail())
              {
                                 cerr<<"No file exists";
                       exit(1);
              }
              outfile.open(fname2);
              if(outfile.fail())
              {
                       cerr<<"Unable to create";
                       exit(1);
              }
              while(!infile.eof())
              {
                       ch = (char)infile.get();
                       upperch = toupper(ch);
                       outfile.put(upperch);
              }
              infile.close();
              outfile.close();
      }




134                     Object Oriented Programming C++
PROGRAM 7.10
Write a program to accept file name of an existing file from user and display the
contents of the file on screen.
      #include<iostream.h>
      #include<conio.h>
      #include<fstream.h>
      void main()
      {
       char name[30],ch;
       fstream file;
       clrscr();
       cout<<"Enter name of file(in BIN folder) to be opened";
       cin>>name;
       file.open(name,ios::in);
       while(file.eof()!=1)
       {
        file.get(ch);
        cout<<ch;
       }
       file.close();
       getch();
      }

PROGRAM 7.11
Write a program to accept two file names from user i.e. source and destination file
name and copy contents of source file into destination file.
      #include<iostream.h>
      #include<conio.h>
      #include<fstream.h>
      void main()
      {
       char sname[30],dname[30],ch;
       fstream sfile,dfile;
       clrscr();
       cout<<"Enter name of source file(in BIN folder)";
       cin>>sname;
       cout<<"Enter name of destination file";
       cin>>dname;
       sfile.open(sname,ios::in);
       dfile.open(dname,ios::out);
       while(sfile.eof()!=1)




          Basic Function of I/O System Basics and File Processing                   135
       {
        sfile.get(ch);
        dfile.put(ch);
       }
       sfile.close();
       dfile.close();
       getch();
      }

PROGRAM 7.12
Write a program to accept and store roll no., name and percentage for 5 students
in a file and display the data by reading it from the file.
      #include<iostream.h>
      #include<conio.h>
      #include<fstream.h>
      #include<string.h>
      void main()
      {
       fstream file;
       file.open("Student.txt",ios::in|ios::out);
       char name[20],hname[20];
       int roll_no,hroll,i;
       float per;
       clrscr();
      for(i=0;i<5;i++)
       {
        cout<<endl<<"Enter name,roll no. and percenatge of the student";
        cin>>name>>roll_no>>per;
        file<<name<<" "<<roll_no<<" "<<per<<endl;
       }
       cout<<endl;
       file.seekg(0);
        for(i=0;i<5;i++)
       {
        file>>name;
        file>>roll_no;
        file>>per;
        cout<<name<<" "<<roll_no<<" "<<per<<endl;
       }
       file.close();
       getch();




136                      Object Oriented Programming C++
      }

PROGRAM 7.13
Write a program to store employee name and basic salary for 5 employees in a file
and display the names of only those employees who have basic salary greater than
5000 by reading data from the file.
      #include<iostream.h>
      #include<conio.h>
      #include<fstream.h>
      #include<string.h>
      void main()
      {
       struct employee
       {
        char name[30];
        float sal;
       }e;
       fstream file;
       file.open("employee.txt",ios::in|ios::out|ios::binary);
       int i;
       float sal;
       clrscr();
      for(i=0;i<5;i++)
       {
        cout<<endl<<"Enter name and salary of employee";
        cin>>e.name>>e.sal;
        file.write((char *)&e,sizeof(e));
       }
       cout<<endl;
       file.seekg(0);
       cout<<endl<<"Employees with salary greater than 5000"<<endl;
        for(i=0;i<5;i++)
       {
        file.read((char *)&e,sizeof(e));
        if(e.sal>5000)
         cout<<e.name<<" "<<e.sal<<endl;
       }
       file.close();
       getch();
      }




          Basic Function of I/O System Basics and File Processing             137
PROGRAM 7.14
Write a program to open an existing file in read mode and count the number of
spaces, new line characters and tabs in the file.
      #include<iostream.h>
      #include<conio.h>
      #include<fstream.h>
      void main()
      {
       fstream file;
       char ch;
       int count1=0,count2=0,count3=0;
       clrscr();
       file.open("Student.txt",ios::in);
       while(file.eof()!=1)
       {
        ch=file.get();
        if(ch==' ')
         count1++;
        else if(ch=='\n')
         count2++;
        else if(ch=='\t')
         count3++;
       }
       cout<<endl<<"There are "<<count1<<" spaces";
       cout<<endl<<"There are "<<count2<<" new line characters";
       cout<<endl<<"There are "<<count3<<" tabs";
        file.close();
       getch();
      }

7.4.2 Binary File operations
     C++ supports binary file operations.
     By default the file operation mode is text.
     A binary file is a sequential access file where the data is stored and read
      back one after another in a binary format instead of ASCII.
      The binary file processing is well-suited for the design and development of
      a complex database or to read and write binary information.




138                     Object Oriented Programming C++
     The text file created by C++ can be edited by an ordinary editor or by a word
      processor.
     The text file can easily be transferred from one compiler to another.
     On the other hand, a binary file is more accurate for numbers because it
      stores the exact internal representation of a value.
     There are no conversion errors or round-off errors.
     Saving data in binary format can be faster as there is no other conversion
      taking place while storing the data to the file.
     Binary format data takes less space.
     Binary format data cannot be transferred from one machine to another, due
      to variations in the inter representation of data of different computers.
      The syntax is
       infile(“data”, ios::binary);
      read( ) and write( ) functions
     The data is stored in the binary file in the similar manner they are stored in
      the internal memory.
     infile.read ( ( char *) & V , sizeof ( V ) );
     oufile.write ( ( char *) & V , sizeof ( V ) );
     In the above two syntaxes V is the address of the variable.
     The sizeof ( ) is the length of that variable in bytes.
     The address of the variable should be pointer to character type.
7.4.3 Error handling using file operations
As we humans also make mistakes while performing tasks, the data to be written
on to the files encounters few errors like
     The file name we are trying to open for new file already exists.
     We may violate the rules while writing the file names.
     We may try to read from the file, which is not opened.
     We may try to write in to the file, which does not exist.
     Trying to write to the file, which has already encountered end of file.
     The different error handling functions are




          Basic Function of I/O System Basics and File Processing                 139
      eof( )         Returns true if end of file is reached.
      fail( )         returns true when input or output operation
      has failed .
      bad( )         Returns true for an invalid operation .
      good( )        Returns true if no error is encountered.


7.5 COMMAND LINE ARGUMENTS (CLA)
      This features adds up to the arguments in the main( ) function.
      These arguments are supplied at the time of invoking the program.
      These are usually used to pass the name of the data files.
      C > results summer vesp
      A result is the name of the file containing the program to be executed.
      Summer and vesp is the file names passed to the program using command
       line arguments.
      CLA are typed by the user and separated using a space.
      The first argument is the name of the file from where the program is to be
       executed.
      The main( ) function can take two arguments as
                       main ( int argc , char * argv [ ] )
      The argc( ) represents the number of arguments in the command line.
      argc( ) is known as argument counter.
      The argv( ) is an array of character type pointer that points to the command
       line arguments.
      The size of this array will be equal to argc( ).
      The argv( ) is known as argument vector.
      For the above command line the value of argc is 3 and argv array pointer as
       argu[0] as results and argu[1] as summer and argu[2] as vesp




140                       Object Oriented Programming C++

								
To top