关于替换字符串的有关问题

关于替换字符串的问题
输入一段话,这个程序替换这段话中所有四个字母单词为love。运行后发现无法显示"Continue? Press Y or y:这段话,也不显示按任意键继续,为什么?

#include<string>
#include<cctype>
#include<iostream>
using namespace std;
int main()
{
char ans;
string str1, str;
do
{
cout << "Enter a passage: ";
cin >> str;
if ((str1.length() == 4) && (isalpha(str1.at(3))))
{
str = "Love";
}
cout << str << " ";
while (cin >> str)
{

if ((str.length() == 4) && (isalpha(str.at(3))))
{
str = "love";
}
if ((str.length() == 5) && (!isalpha(str.at(4))))
{
cout << "love" << str.at(4) << " ";
continue;
}
cout << str << " ";
}
cout << '\n';
cout << "Continue? Press Y or y: ";
cin >> ans;
} while (ans = 'Y' || ans == 'y');

return 0;
}
------解决方案--------------------
"Continue? Press Y or y:这句要到while (cin >> str)这个循环结束才能显示,结束循环的条件是输入Ctrl+Z(windows, Ctrl+D in linux)
------解决方案--------------------
while (ans = 'Y' 
------解决方案--------------------
 ans == 'y');
这句不是死循环吗?
------解决方案--------------------
少了个等号
while (ans = 'Y' 
------解决方案--------------------
 ans == 'y');
------解决方案--------------------
引用:
加了=号还是没用


因为 while (cin >> str) 这个循环一直没有结束,所以根本没有运行到那一句。。。

如果你手动 Ctrl+Z (Linux下是Ctrl+D)输入结束符让循环结束,外面的 while (ans = 'Y' 
------解决方案--------------------
 ans == 'y') 又会陷入死循环

所以你最好把 while (cin >> str) 改成 if (cin >> str)