In this program, although I use Ignore(1000,’\n’); why it does not show the title for tape.
In fact, I don’t understand very well about Ignore(); what is the meaning of 1000 in that function?

#include<iostream.h>
class Publication
{
 char title[20];
 float price;

 public:
 void putdata()
 {
 cout<<"\nEnter title:";
 cin.getline(title,20);
 cin.ignore(1000,'\n');
 cout<<"\nEnter price:";
 cin>>price;
 }

 void getdata()
 {
  cout<<"\nTitle:"<<title;
  cout<<"\nPrice:"<<price;
 }

};

class Book:public Publication
{
 int pgcount;

 public:
 void putdata()
 {
  Publication::putdata();
  cout<<"\nEnter page count";
  cin>>pgcount;
 }
 void getdata()
 {
  Publication::getdata();
  cout<<"\nPage Count:"<<pgcount;
  }


};

class Tape:public Publication
{
 float ptime;

 public:

 void putdata()
 {

  Publication::putdata();
  cout<<"\nEnter playing time:";
  cin>>ptime;
 }

 void getdata()
 {
  Publication::getdata();
  cout<<"\nPlaying time:"<<ptime;
 }
 };

int main()
{
 Book b1;
 Tape t1;

 b1.putdata();
 t1.putdata();
 b1.getdata();
 t1.getdata();
 return 0;
 }

>why it does not show the title for tape.
It does, but the title happens to be an empty string. You're suffering from the problem described in the first paragraph of this sticky.

>what is the meaning of 1000 in that function?
The first argument is a maximum limit, it means read and discard up to that many characters. The second argument augments the first argument and acts as a delimiter. It says to stop discarding early (before reaching the maximum limit) if a specific character is found.

All in all, ignore says to read and discard up to N characters (first argument) or until the specified character is detected (second argument).

This article has been dead for over six months. Start a new discussion instead.