C++从句子中删除给定字符的程序不起作用
C++ Program to Remove given Character from the sentence doesn't work
程序只是从第一个单词中删除字符,而不是从所有句子中删除字符。我该怎么修?我需要删除句子中的所有字符,而不仅仅是第一世界。谢谢
#include <iostream>
#include <string>
#include <algorithm>
int main()
{
std::string s;
char c;
std::cout << "Enter the string : ";
std::cin >> s;
std::cout << "nEnter the character : ";
std::cin >> c;
/* Removing character c from s */
s.erase(std::remove(s.begin(), s.end(), c), s.end());
std::cout << "nString after removing the character "
<< c << " : " << s;
}
你没有阅读整句话。您可以使用getline:
std::cout << "Enter the string : ";
std::getline(std::cin, s);
Godbolt 直播
相关文章:
- 我的目标是编写一个程序来计算和存储字符串在字符数组中出现的位置
- C++ 电话号码字母拨号程序 - 语法错别字?还是非 ASCII 字符?
- 有人可以在下面的示例 C++ 程序中解释字符数组 KCHAR1 的奇怪行为吗?
- c ++控制台应用程序,如何在控制台外部打印字符
- 为 Sql 服务器实现 odbc 包装器.将数据库数据读取为字符或要求驱动程序将数据转换为 C 类型
- C++ |为什么执行此程序后我会得到奇怪的字符?
- C ++程序在字符数组中插入单词
- C++从句子中删除给定字符的程序不起作用
- 程序,它接受用户输入的字符并按出现的降序显示它们
- 找不到如何创建使用指针、字符和 for 函数组合的程序
- 编写一个程序,输入整数 n 并打印该数字的字符数(符号除外)
- 程序输出奇怪的字符
- C++程序,将整数输入转换为字符的问题
- 将 C 程序转换为具有大量字符* 和无符号字符转换错误的C++
- 使用独立的 c++ 程序处理用 C 编写的字符设备驱动程序
- Visual C 32位整数从文件到8位字符到文件 - 程序在某些整数上崩溃
- C 程序仅在字符阵列获得“ 1000!”的输入时才在DELETE上崩溃
- 当我们在以下程序(C )中输入字符时,该如何解决
- ASCII 和字符程序
- 将 C 字符串分配给字符 - C++程序崩溃