视觉程序在C++中使用VECTORS删除不喜欢的单词?[这是PPP第4章中的"Try This"问题]
visual Program to remove disliked words using VECTORS in C++? [This is a "Try This" quesn in PPP Chapter 4]
#include "..//..//std_lib_facilities.h"
int main()
{
vector<string>disliked ;
cout<<" Enter the words you don't like :- ";
string dis;
while(cin>>dis)
{disliked.push_back(dis);
cout<<"To terminate the input press ctrl+Z";
}
cout<<"Enter a sentence :-";
vector<string>sentence;
string word;
while(cin>>word)
{
sentence.push_back(word);
cout<<"To terminate the input press ctrl+Z";
}
for(unsigned int i=0;i<sentence.size();i++)
{for(unsigned int n=0;n<disliked.size();n++)
{if (sentence[i] == disliked[n])
sentence[i] = "Bleep";
}
cout<<sentence[i];
}
}
当我运行程序时,执行在第一次输入后停止。它不允许我在句子向量中输入单词
一旦输入流接收到文件结束条件,所有进一步从输入流读取的尝试,而不仅仅是第一次尝试,将以文件结束条件失败。
因此,当您使用CTRL-Z在标准输入上发送文件结束时,当您试图从输入流中读取更多输入时,您继续在输入流上接收文件结束条件。
尽管在交互式终端中可能有也可能没有清除文件结束条件的方法,但最简单的方法是找到其他方法来表示第一组输入的结束,而不是按CTRL-Z表示文件结束。
相关文章:
- 使用递归的数组的最小值.这是怎么回事
- 我不小心调用了一个没有自己类对象的成员函数.但这是怎么回事呢
- 这是我尝试让用户将值输入到数组中.然后将其隐藏为大量的星号
- 这是实现图形的坏方法吗
- 当基类是依赖类型时,这是一个缺陷吗
- 当C++中需要自动删除时,这是静态的正确用法吗?
- 这是关于成员访问规则的正确摘要吗
- 这是插入排序的正确实现吗?
- 我使用 OpenMP 的线程越多,执行时间就越长,这是怎么回事?
- 如何在OpenCV中检测这是谁的脸?
- 这是使用回溯的 nqueen 问题,但我使用了动态 2d 数组,我的程序编译良好,但不返回任何输出
- 在 Python 和 c++ 2d 数组初始化之间.这是怎麽?为什么呢?
- 验证openssl c++中的签名,这是由JAVA DSA签名的?
- 这是GoogleTest AssertionResult中的错误吗?
- 在编译时,C++项目抛出错误 C2228,这是预期的,因为控件在运行时未达到该点
- 这是 basic.def.odr 部分的缺陷吗?
- 被覆盖的函数不会反映在基类中,这是正常行为吗?
- MSVC 无法根据模板参数进行数学运算,这是一个错误吗?
- 这是 ubuntu 16.04 中的 gdb 错误吗?
- 视觉程序在C++中使用VECTORS删除不喜欢的单词?[这是PPP第4章中的"Try This"问题]