String character removal

Hi,

I know how to remove certain characters from a string by using something like this

1
2
  string str ("Hello world!");
  erase (0, 6);


That's great if I want to do that manually, but say if someone entered a string, how would I automatically remove every other character they entered? Sorry if this is a poor explanation, but I hope someone can help me.

-Joe
Off the top of my head.

Use a for loop get the length of the string and then erase.
Let me know if you have any questions.
1
2
3
4
5
6
string str;
getline(cin, str);

int i = 0;
while( ++i < str.length() )
    str.erase( i, 1 );
Thank you, I feel stupid now
Topic archived. No new replies allowed.