Simple Program for Read & Write File Operation (Convert lowercase...
On this page (6sections)
program to convert lowercase to uppercase.
Simple Program for Reading & Write File Operation (Convert lowercase to uppercase) Algorithm/Steps:
- STEP 1: Start the program.
- STEP 2: Declare the variables.
- STEP 3: Read the file name.
- STEP 4: open the file to write the contents.
- STEP 5: writing the file contents up to reach a particular condition.
- STEP6: write the file contents as uppercase.
- STEP7: open the file to read the contents.
- STEP 8: Stop the program.
Read & Write File Operation (Convert lowercase to uppercase) Program
#include<fstream.h>
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<iostream.h>
#include<conio.h>
void main() {
char c, u;
char fname[10];
clrscr();
ofstream out;
cout << "Enter File Name:";
cin>>fname;
out.open(fname);
cout << "Enter the text(Enter # at end)\n"; //write contents to file
while ((c = getchar()) != '#') {
u = c - 32;
out << u;
}
out.close();
ifstream in(fname); //read the contents of file
cout << "\n\n\t\tThe File contains\n\n";
while (in.eof() == 0) {
in.get(c);
cout << c;
}
getch();
}
Sample Output
Enter File Name: two.txt
Enter contents to store in file (enter # at end)
oops programming
The File Contains
OOPS PROGRAMMING
How It Works
This C++ program demonstrates Simple Program for Read & Write File Operation (Convert lowercase… It first reads the required values as input, then walks through the data with a loop to compute the result, and finally prints the output shown in the Sample Output above.
- Declare the variables that hold the program’s data.
- Read the input values that the program will work with.
- Iterate over the data using a loop to apply the logic.
- Print the final result to the console so you can compare it with the sample output.
Try changing the input values and re-running the program to see how the output changes — this is the fastest way to understand how the logic behaves.
Related Pages
Learn the concept first, then study the code:
- C++ Programs — Browse all C++ Programs.
Frequently Asked Questions
What does this C++ program do?
It is a C++ example program that demonstrates Simple Program for Read & Write File Operation (Convert lowercase..., including the complete source code and the expected sample output.
How do I compile and run this C++ program?
Save the code in a `.cpp` file, compile it with `g++ filename.cpp -o program`, then run it with `./program` (or `program.exe` on Windows).
What concepts does this example use?
This example uses loops to iterate over data, arrays and reading user input, illustrating a common pattern in C++ programming.