Object Oriented Programming Practical 23
Question 1
Write a C++ program to Read and Display File's Content.
read.cpp
C
#include<fstream.h>
#include<conio.h>
void main()
{
clrscr();
char c;
ifstream fin;
fin.open("abc.txt");
char a;
while(fin)
{
fin.get(a);
cout << a;
}
fin.close();
getch();
}
Output

Question 2
Write a C++ program to List Files in Current Directory.
list.cpp
C
#include<fstream.h>
#include<conio.h>
#include<dirent.h>
void main()
{
clrscr();
DIR *dr;
struct dirent *en;
dr = opendir(".");
if (dr)
{
en= readdir(dr);
while (en!= NULL)
{
cout<<" \n"<<en->d_name;
en= readdir(dr);
}
closedir(dr);
}
getch();
}
Output
