I am doing an exercise in a book im currently reading and it goes like this:
Write a program that reads a string of characters including punctuation
and writes what was read but with the punctuation removed.
This is how i did it:
1 2 3 4 5 6 7 8 9 10 11
string x("#punctuation!?=");
cout << x << endl;
for(unsigned i = 0; i < x.size(); ++i)
{
if(ispunct(x[i]))
x[i] = ' ';
}
cout << x << endl;
i am just not sure if thats how they want you to do it because it doesn't
remove the punctuations it just replaces them with a space.
#include <iostream>
#include <string>
#include <cctype>
int main()
{
const std::string jabberwocky = "'Twas brillig, and the slithy toves\n""Did gyre and gimble in the wabe;\n""All mimsy were the borogoves,\n""And the mome raths outgrabe.\n\n""\"Beware the Jabberwock, my son\n""The jaws that bite, the claws that catch!\n""Beware the Jubjub bird, and shun\n""The frumious Bandersnatch!\"\n" ;
std::cout << jabberwocky << "\n-----------------------\n\n" ;
for( char c : jabberwocky ) // http://www.stroustrup.com/C++11FAQ.html#forif( !std::ispunct(c) ) std::cout << c ;
}