Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to replace underscore with space in std::string

0 views
Skip to first unread message

Jason Heyes

unread,
Jun 8, 2005, 11:27:47 AM6/8/05
to
What is a nice STL statement/s to replace each occurance of the underscore
character ('_') with a space character (' ') in a std::string? Thanks.


James Daughtry

unread,
Jun 8, 2005, 11:35:55 AM6/8/05
to
std::replace, perhaps?

#include <algorithm>
#include <iostream>
#include <string>

int main()
{
std::string s("this is a test");

std::replace(s.begin(), s.end(), ' ', '_');
std::cout << s << '\n';
}

Richard Herring

unread,
Jun 8, 2005, 12:02:30 PM6/8/05
to
In message <42a70e73$0$10319$afc3...@news.optusnet.com.au>, Jason Heyes
<jason...@optusnet.com.au> writes

>What is a nice STL statement/s to replace each occurance of the underscore
>character ('_') with a space character (' ') in a std::string? Thanks.

What is a nice STL template algorithm to replace each occurrence of some
particular value with some other value in an arbitrary sequence? What do
you think it might be called?

--
Richard Herring

0 new messages