0% found this document useful (0 votes)
27 views2 pages

Program 11

This C++ program reads a text file named 'arith.txt' and displays its contents line by line, numbering each line. It checks for errors when opening the file and handles end-of-file conditions. The program uses basic file handling and console input/output operations.
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)
27 views2 pages

Program 11

This C++ program reads a text file named 'arith.txt' and displays its contents line by line, numbering each line. It checks for errors when opening the file and handles end-of-file conditions. The program uses basic file handling and console input/output operations.
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

PROGRAM 11

#include <iostream.h>
#include <conio.h>
#include <fstream.h>
#include <process.h>
void main()
{
fstream fin;
char ch;
int lineNumber = 1;
clrscr();
[Link]("[Link]", ios::in);
if (!fin)
{
cout << "Error opening file!" << endl;
getch();
exit(1);
}

cout << lineNumber << ":";


while (![Link]())
{
[Link](ch);
if (ch != '\n')
{
cout << ch;
}
else
{
cout << endl;
if (![Link]())
{
lineNumber++;
cout << lineNumber << ":";
}
}
}
[Link]();
getch();
}

You might also like