character replace

How would I replace a space " " with and underscore "_"?
std::string has some functions you might want to look at.

http://www.cplusplus.com/reference/string/string/
<stating obvious> Simply assign an underscore to each character which holds a space. Without further information, we can't be more specific. Is the space character in a string object, a char array or what?
Thanks for the fast replies, Zhuge and sammy34.

This program receives a information and formats it so it can be uploaded and used on the website. The characters in char[] items_title are same as char[] image_name expect for the spaces. Rather than inputting the same info 2x I want to replace the spaces " " in items_title with underscores.

"broken house junk" becomes "broken_house_junk.jpg"

@Zhuge, I looked at your link. It didn't make much sense but when I finish with the rest of this program I will take more time and try to make sense of it. Thank you.

@Sammy, "Simply assign an underscore to each character which holds a space."
What does that mean?
Last edited on
This one may be used on character arrays:
http://www.cplusplus.com/reference/algorithm/replace/
Topic archived. No new replies allowed.