编程论坛
注册
登录
编程论坛
→
C++教室
C++编程
烟雨霏微
发布于 2018-11-06 23:28, 1203 次点击
从键盘输入一个字符串,删除字符串中的所有空格后输出这个字符串。(C++)
3 回复
#2
rjsp
2018-11-07 08:42
不清不楚的。
1. “从键盘输入一个字符串” --- 以什么结束输入?回车吗?
2. “所有空格” --- 你确定只需要删除
空格
,而像\t之类的其它
空白字符
不需要删除?
程序代码:
#include
<iostream>
#include
<string>
#include
<algorithm>
using
namespace
std;
int
main(
void
)
{
string
s;
//
输入一行
getline(
cin
, s );
//
删除空格
s.erase( remove(s.begin(),s.end(),
'
'
), s.end() );
//
输出
cout
<< s << endl;
}
#3
林娜客塞
2018-11-07 17:55
我也学学。
#4
烟雨霏微
2018-11-07 21:04
题目就是这么写的,我也没办法啊
1