replace all '.' to space in a string?

I have an ip address represented by a string like "192.168.1.1", is there any simple ways for me to conver all the '.' to spaces in this string?

1
2
3
string ip("192.168.1.1");
// how to convert?
......


The output should be:
192 168 1 1

Easiest way, IMO:
1
2
3
4
#include <algorithm>

  string ip("192.168.1.1");
  replace(ip.begin(), ip.end(), '.', ' ');


String has a set of replace member functions that offer a lot of flexibility, but for single character replace the std algorithm replace is much simpler and avoids writing a loop yourself.
Topic archived. No new replies allowed.