So the assignment is changing all 4-letter word to 'love', for example if my input is
"Ice cube cold"
It'll give output : "Ice love love"
The thing is, I've done until that part until the assignment told me to change word that start with capital letter as 'Love'. For example if my input is
"Cold hot Cube"
It'll give output : "Love hot Love"
I've been doing the assignment and stuck on 2nd part. This is my current code.
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
usingnamespace std;
int main()
{
ifstream input;
ofstream output;
stringstream check_upper;
output.open("4letters.txt");
char next;
cin.get(next);
output << static_cast<char>(toupper(next));
do
{
cin.get(next);
output << next;
} while (next != '\n');
output.close();
input.open("4letters.txt");
string love;
while (input >> love)
{
if (love.length() == 4)
{
char letter[4];
check_upper << love;
check_upper >> letter;
if (isupper(letter[0]))
{
love = "Love";
cout << love << " ";
}
else
{
love = "love";
cout << love << " ";
}
}
else
{
cout << love << " ";
}
}
return 0;
}
I use sstream to check the capital letter of a string, but it only worked for first ecounter, for example the input is "Cold hot cube", the output will become "Love hot Love" and not "Love hot love"