Hello im doing this exercise where i have to open 1 text file and if a letter is uppercase i have to convert it to lowercase and write new content in another file.
So i wrote this function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
class Bad{};
void file_to_lower(string file_name){
ifstream ifs{ file_name+".txt" };
if (!ifs) throw Bad{};
ofstream ofs{ file_name + "_lower.txt" };
if (!ofs) throw Bad{};
char ch;
while (ifs.get(ch)){
if (isupper(ch)) tolower(ch);
ofs << ch;
}
}
The problem is that im getting new file but the content is the same. Still all upper case characters - not a single 1 converted. Why is this happening? Is "tolower()" even working? Or what did i do wrong?
PS: i tested that i successfully got inside my if statement so as far as i understand char should get transformed into lower case one.
just as Mr cire said, u need to store the result returned from the function tower()
you could replace if (isupper(ch)) tolower(ch); withif(isupper(ch)) ch = tolower(ch);