I'm reading from a file that contains an entire book. I'm trying to find out how many similar words there are. I have succeeded in accomplishing what I wanted. However, ass example below shows,
100 : hej
50 : the
40 : apples
37 : banana
30 : <==== // This spaces I don't know where they come from?
20 : go
10 : come
I want my output to be :::
100 : hej
50 : the
40 : apples
37 : banana
20 : go
10 : come
I'm have been using remove_if isspace and iswspace
but it does not work in my case.
Anyone knows how should I think?
Thank you very much!
CodePudding user response:
did you try using lambda? and tell me if the problem is solved:
words.erase(std::remove_if(words.begin(),
words.end(),
[](unsigned char x){
return std::isspace(x);}),
words.end());
CodePudding user response:
or
auto noSpace = std::remove(words.begin(), words.end(), ' ');
words.erase(noSpace, words.end());