/* Hello, I'm attempting to write the function body for removePunctuation w/o loops. I've been playing around w/ the for_each algorithm to remove punctuation from a string s (which seems to be working fine), then copy the results into a new string t. For example, convert "a*^^bc__" to "abc" However, I'm not getting the desired results using the copy algorithm. Does anyone have any suggestions?*/
#include <iostream>
#include <algorithm>
#include <iterator>
using namespace std;
bool isLetter(char c);
string removePunctuation (string s);
int main()
{
string s1="a*^^bc__";
string s2=removePunctuation(s1);;
cout<<"s2="<<s2<<endl;
system("pause");
return 0;
}
bool isLetter(char c)
{
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
}
string removePunctuation (string s)
{
string t;
for_each(s.begin(), s.end(), isLetter);
copy(s.begin(), s.end(), back_inserter(t));
return t;
}
#include <iostream>
#include <algorithm>
#include <iterator>
using namespace std;
bool isLetter(char c);
string removePunctuation (string s);
int main()
{
string s1="a*^^bc__";
string s2=removePunctuation(s1);;
cout<<"s2="<<s2<<endl;
system("pause");
return 0;
}
bool isLetter(char c)
{
return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
}
string removePunctuation (string s)
{
string t;
for_each(s.begin(), s.end(), isLetter);
copy(s.begin(), s.end(), back_inserter(t));
return t;
}