Need a little help.

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.
Line 8 could be:
 
  x[i] = '';

I guess?
It gives me an error if i do that:
error: empty character constant.

I'm not sure what that means.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#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#for
       if( !std::ispunct(c) ) std::cout << c ;
}

http://coliru.stacked-crooked.com/a/8b9f31c8d2e34e11
Topic archived. No new replies allowed.