Simple Program for Read File Operation Using C++ Programming
Program for reading the content of a file.
Simple Program for Read File Operation Algorithm/Steps:
- STEP 1: Start the program.
- STEP 2: Declare the variables.
- STEP 3: Get the file name to read.
- STEP 4: Using ifstreamin(filename) check whether the file exist.
- STEP 5: If the file exists then check for the end of file condition.
- STEP 6: Read the contents of the file.
- STEP 7: Print the contents of the file.
- STEP 8: Stop the program.
Simple Program for Reading File Operation Example
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
void main() {
char c, fname[10];
clrscr();
cout << "Enter file name:";
cin>>fname;
ifstream in(fname);
if (!in) {
cout << "File Does not Exist";
getch();
return;
}
cout << "\n\n";
while (in.eof() == 0) {
in.get(c);
cout << c;
}
getch();
}
Sample Output
Enter File name: one.txt
Master of Computer Applications
(file one.txt contains text "Master of Computer Applications")
Read More Articles
- Simple Merge Sort Program in C++
- Scope Resolution Operator In C++
- Simple Program for Virtual Functions Using C++ Programming
- Simple Class Example Program For Find Prime Number In C++
- Simple Example Program For Parameterized Constructor In C++
- Define Constructor in Outside Class Example Program In C++
- Simple Example Program For Copy Constructor In C++
- Simple Program for Function Overloading Using C++ Programming
- Simple Program for Single Inheritance Using C++ Programming
- Simple Program for Inline Function without Class Using C++ Programming
- Simple Example Program For Constructor Overloading In C++
- Factorial Using Function Example Program In C++
- Simple Example Program for Inline Function Using C++ Programming
- Simple Addition ( Add Two Integers ) Example Program
- Simple Example Program For Constructor In C++
- Simple Program for Read user Input Using cin
- Factorial Using Loop Example Program In C++
- Simple Stack Program in C++ Programming
- Simple Program for Friend Function Using C++ Programming
- Simple Program for Static Data and Member Function Using C++ Programming
- Simple Program for Unary Operator Overloading Using C++ Programming
- Simple Program for Multiple Inheritance Using C++ Programming
- Do While Loop Example Program In C++
- Simple Copy Constructor Example Program For Find Factorial In C++
- Simple Program for Virtual Base Class Using C++ Programming