View Single Post
Old Jan 10th, 2007, 8:57 PM   #5
Bench
Newbie
 
Join Date: Feb 2006
Posts: 20
Rep Power: 0 Bench is on a distinguished road
Quote:
Originally Posted by magnus.therning View Post
I found that the following code works:

int pos;
while((pos = my_string.find_first_of(" ")) != std::string::npos)
  my_string[pos] = '_';

But, very C++ it isn't.
I'd say that this is far more 'C++' ..
    std::string my_string("The quick brown fox jumped over the lazy dog");
    std::replace( my_string.begin(), my_string.end(), 'o', '*' );
Bench is offline   Reply With Quote