0% found this document useful (0 votes)
53 views4 pages

7) Explain Falg iOS:: Binary and iOS::ate

The document discusses file input/output (I/O) streams in C++. It explains that flags can be used when opening files to modify how the file is opened. Specifically, it mentions the ios::app and ios_base::app flags, which append data to an existing file rather than overwriting it. It provides examples of using these flags when constructing an ofstream object. The document also notes that binary files can be used to store data in C++ and provides a sample program to demonstrate writing structured data to a binary file.

Uploaded by

Om Pawar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views4 pages

7) Explain Falg iOS:: Binary and iOS::ate

The document discusses file input/output (I/O) streams in C++. It explains that flags can be used when opening files to modify how the file is opened. Specifically, it mentions the ios::app and ios_base::app flags, which append data to an existing file rather than overwriting it. It provides examples of using these flags when constructing an ofstream object. The document also notes that binary files can be used to store data in C++ and provides a sample program to demonstrate writing structured data to a binary file.

Uploaded by

Om Pawar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

7 ) explain falg iOS :: binary and iOS ::ate

When you open a file by constructing either an ofstream or ifstream instance, you can


modify the way the file will open by supplying what are called flags. In computer terms,
a flag is simply a small item whose presence or lack of presence tells a function how to
do something. With the ofstream and ifstream classes, the function in question is the
constructor.

A flag looks like ios::app if you’re using a compiler that is not fully ANSI-compliant, or
looks like ios_base::app if you’re using one that is fully ANSI-compliant. This particular
flag means that you want to write to a file, but you want to append to any existing data
that may already be in a file. You supply this flag as an argument of the constructor
for ofstream, as in either of the following examples:

ofstream outfile("AppendableFile.txt", ios::app);


ofstream outfile("AppendableFile.txt", ios_base::app)

12) explain the function used to read and write data in binary file.

 When a program is terminated, the entire data is lost. Storing in a file will
preserve your data even if the program terminates.

 If you have to enter a large number of data, it will take a lot of time to enter
them all.
However, if you have a file containing all the data, you can easily access the
contents of the file using a few commands in C.
 You can easily move your data from one computer to another without any
changes
13) what is difference between manipulator and iOS member function in implementation? Give
examples.

 ios functions returns value while manipulators does not.  

 we can not create own ios functions while we can create our own
manipulators.  

 ios functions are single and not possible to be combined while


manipulators are possible to be applied in chain.  

 ios function needs while manipulators needs  

 ios functions are member functions while manipulators are non-member


functions.

17) explain the use of use of binary files in c++ with a program

The insertion and extraction operators (i.e. << and >> are meant to be used by


programs for writing to and reading from text files; it is assumed that the
programmer is familiar with the differences between these two file formats

struct Person
{
  char name[50];
  int age;
  char phone[24];
};

int main()
{
  Person me = {"Robert", 28, "364-2534"};
  Person book[30];
  int x = 123;
  double fx = 34.54;
  ofstream outfile;
  outfile.open("junk.dat", ios::binary | ios::out);
  outfile.write(&x, sizeof(int)); // sizeof can take a type
  outfile.write(&fx, sizeof(fx)); // or it can take a variable name
  outfile.write(&me, sizeof(me));
  outfile.write(book, 30*sizeof(Person))
  outfile.close();
}

20) write a program to store employee names with their designation and net pay to file a console also
display employee details from file .create a class employee.

class Employee
  {
        public string name;
        public int salary;
        public int joiningDate;

        public Employee()
    {
    }
        public Employee(string name, int salary, int joiningDate)
    {
            this.name = name;
            this.salary = salary;
            this.joiningDate = joiningDate;
    }
        public void GetEmployeeData()
    {
      {
                Console.WriteLine("Enter the name of employee: ");
                name = Convert.ToString(Console.ReadLine());
                Console.WriteLine("Enter the salary of employee: ");
                salary = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Enter the date of joining of employee: ");
                joiningDate = Convert.ToInt32(Console.ReadLine());
      }
    }
        public void DisplayEmployee()
    {
            Console.WriteLine("The name of employee is: "+ name);
            Console.WriteLine("The salary of employee is: "+salary);
            Console.WriteLine("The date of joining of employee is: "+joiningDate);
    }
  }
    class Program
  {
        static void Main(string[] args)
    {
            Employee[] e = new Employee[10];
            for(int i = 0; i < 10; i++)
      {
                 Console.WriteLine($"Enter the data of employee with id: {i}
*****************************************");
                e[i] = new Employee();
                e[i].GetEmployeeData();
      }
            Console.WriteLine("***********The data of given employees is: ");
            for(int i = 0; i < 10; i++)
      {
                e[i].DisplayEmployee();
      }
    }
  }

You might also like