Answer to Question #84599 in C++ for Yash

Question #84599
Q12. A user has written a cpp program in capital case and saved it as "my.cpp". Since C++ recognizes only lower case, write a program to read the above file and convert the entire program to lower case and save it to another file named "mynew.cpp".
1
Expert's answer
2019-01-28T05:50:22-0500

#include <iostream>

#include <fstream>

#include <cctype>

#include <cstring>


using namespace std;


int main( ){

ifstream fin;

ofstream fout;

fin.open("my.cpp");

fout.open("mynew.cpp");

string str;

while (!fin.eof()) {

getline(fin, str);

int n;

n = str.length();

for (int i = 0; i < n; i++) {

if (isalpha(str[i]))

fout << static_cast<char>(tolower(str[i]));

else

fout << str[i];

}

fout<< endl;

}

fin.close();

fout.close();

return 0;

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS