Ok so here's a question I got. I want to replace a single character in a string lets say it's '+'. The string is "five + five". How exactly should i do that? I know i need a four loop but I'm confused about how to use std::replace.
1 2 3 4 5 6
string swag" five + five";
for (int i = 0; i< swag.length(); i++)
{
}
std::string dwag = "five + five" ;
// replace the first occurrence of '+' with '*'
// step 1: locate the position of the first '+'
// http://www.cplusplus.com/reference/string/string/find/constauto pos = dwag.find( '+' ) ;
// step 2: if the '+' was found, replace it with '*'
if( pos != std::string::npos ) dwag[pos] = '*' ;
// replaces the first '+' with '*'
string swag = " five + five";
for (size_t i = 0; i < swag.length(); i++)
{
if (swag[i] == '+')
{
swag[i] = '*';
break;
}
}