How to replace underscore with space in std::string

J

Jason Heyes

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

James Daughtry

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';
}
 
R

Richard Herring

Jason Heyes said:
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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top