You are on page 1of 2

15.

Write a program in file that will take two inputs as


starting index and ending index and give output that will
hold the contents between the indexes.

/* Implementation of File
Created by: Biplob Banik
*/

#include<iostream>
#include<fstream>
#include<conio.h>
using namespace std;
int main(){
ifstream infile("D:\\New folder\\CPP\\fst");
int m,n;
cout<<"Enter the starting index"<<endl;
cin>>m;
cout<<"Enter the ending index"<<endl;
cin>>n;

int i=0;
char text[100];
while(infile){
i++;
infile.getline(text,100);
if(i>=m && i<=n)
cout<<text<<endl;
}
getch();
return (0);
}
Output:

Discussion:
In this program we at first create a notepad file and something into it.
Then we code a program that will take a starting index and an ending index
from the user and give the contents between the given line numbers .

_________________________________

Signature with date

You might also like