我尝试使用
代码如下:
我预计这应该只会简单地打印出:
但是我却得到了:
std::remove_if
来从简单字符串中删除空格,但结果很奇怪。可以有人帮助我弄清楚发生了什么吗?代码如下:
#include <iostream>
#include <algorithm>
#include <string>
int main(int argc, char * argv[])
{
std::string test = "a b";
std::remove_if(test.begin(), test.end(), isspace);
std::cout << "test : " << test << std::endl;
return 0;
}
我预计这应该只会简单地打印出:
test : ab
但是我却得到了:
test : abb
尝试使用另一个字符串,我得到:
输入:"a bcde uv xy"
输出:"abcdeuvxy xy"
似乎是复制了最后一个“单词”,但有时会添加一个空格。如何才能使其只删除所有空格而不出现奇怪的情况?