word replace.

hi

how can I make one of the underscore on line elleven change to some letter/
I tried to put
p.replace(p.begin(),p.begin()+pos+1,letter);
in the for loop but it changes everything into that certain letter exept first underscore.
I know possition of a letter i want to change, because i have done
possition = word.find(letter)+1;
but i can t get to change just one letter.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void x (string word, string letter, int pos, int length)
{

     if (word.find(letter)+1)
     {  

        intro();
        
            for (int i = 0; i<length; i++)
                {
                     p="_";
                     cout<<p;                       
                }
                
     cout <<endl<<endl;   
     }          
        
}


any help would be appreciate.
Last edited on
I have understood nothing. But maybe this code will be useful for you

std::string::size_type pos = word.find( '_' );

if ( pos != std::string::npos ) word[pos] = letter;
Last edited on
Topic archived. No new replies allowed.