Skip to content

Commit

Permalink
Revert "fix bug"
Browse files Browse the repository at this point in the history
This reverts commit bff10a6.
  • Loading branch information
Queequeg92 committed Nov 23, 2014
1 parent bff10a6 commit 72c0f3d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions ch11/ex11_3_4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@
#include <cctype>
#include <algorithm>

void remove_punct(std::string &s)
{
auto iter = s.begin();
while(iter != s.end())
{
if(std::ispunct(*iter))
{
iter = s.erase(iter);
}
else
++ iter;
}
}

//! Exercise 11.4
void word_count_pro(std::map<std::string, int> &m)
Expand All @@ -23,9 +36,7 @@ void word_count_pro(std::map<std::string, int> &m)
while(std::cin >> word)
{
for(auto& ch : word) ch = std::tolower(ch);
//! Erase-remove idiom
//! http://en.wikipedia.org/wiki/Erase-remove_idiom
word.erase(std::remove_if(word.begin(), word.end(), ispunct), word.end());
remove_punct(word);
++m[word];

for (const auto &e : m)
Expand Down

0 comments on commit 72c0f3d

Please sign in to comment.