x

Choose Country Code

x

Direction

x

Ask a Question

  • Ask a Question
  • Scan a Question
  • Post MCQ
  • Note: File extension must be of jpg, jpeg, png, bmp format and file size must not exceed 5 MB
x

Ask a Question

x

x
x
x
Hire a Tutor

Answers and Solutions

What's Your Question?
Answer

Example by code:-

#include<iostream.h>

#include<conio.h>

#include<fstream.h>

#include<stdio.h>

#include<stdlib.h>

class Video {

private:

int vid_id,qty_cd;

char n,movie[50],director[50];

float price;

 

public:

void addVideo();

void showLib();

}v;

 

void Video :: addVideo() {

ofstream out;

out.open("VIDEOLIB.DAT",ios::app);

 

cout<<"\n Enter Video ID : ";

cin>>vid_id;

cout<<"\n Enter Movie Name : ";

fflush(stdin);

gets(movie);

cout<<"\n Enter Director Name : ";

fflush(stdin);

gets(director);

cout<<"\n Enter Quantity Of CD's : ";

cin>>qty_cd;

cout<<"\n Enter Price for the Movie(in $) : ";

cin>>price;

out<<vid_id<<"\t"<<movie<<"\t"<<director<<"\t"<<qty_cd<<"\t"<<price<<endl;

out.close();

}

 

void Video :: showLib() {

ifstream in;

in.open("VIDEOLIB.DAT",ios::in);

if(!in) {

cout<<"\n File is Empty " ;

}

while(in) {

in.get(n);

cout<<n;

}

in.close();

}

 

void main() {

int c;

do {

clrscr();

cout<<"\n\t MENU\n\t======\n";

cout<<"\n To Add Video........Press 1 ";

cout<<"\n To Show Library.....Press 2 ";

cout<<"\n To Exit.............Press 0 \n";

cout<<"\n Enter Your Choice : ";

cin>>c;

switch(c) {

case 0 :exit(0);

case 1 :v.addVideo();

break;

case 2 :v.showLib();

break;

default: cout<<"\n Invalid\n Press any key...";

}

getch();

}while(c!=0);

}

Answer

Basic Operation On Text File In C++ 

File I/O is a five-step process: 1. Include the header file fstream in the program. 2. Declare file stream object. 3. Open the file with the file stream object. 4. Use the file stream object with >>, <<, or other input/output functions. 5. Close the files.

Post Answer and Earn Credit Points

Get 5 credit points for each correct answer. The best one gets 25 in all.

Post Answer