C++编程
从键盘输入一个字符串,删除字符串中的所有空格后输出这个字符串。(C++)
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;
}







