problem with string replace (char *)

It's been a long time I didn't program with C++ (i have been working with java which i am not a fan), so i decide to practice.

I'm trying to make a hangman but I have a problem with string replace it keeps saying invalid conversion from char to const char.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Hangman h("testo"); //class that only contains a string attribute
	string t;	
	t.insert(0,h.getWord().length(),'*');
	char m;
	int b; 
	
	cout<<"enter a letter \n";
	cin>>m;
	
	b = h.getWord().find(m);


	if ( b >= 0){
		t.replace(b,1,h.getWord().getWord()[b]);
                //t.replace(b,1,h.getWord().getWord()[b]+""); 
                //returns string::copy with '*'
	}


and if I try t.replace(b,1,h.getWord().getWord()[b]+""); (a way in java to convert into string) and I enter 'e' it gives : *string::copy***

thanks in advance
closed account (E0p9LyTq)
Are you trying to replace individual characters in a C++ std:string? If you are, then you might want to look at std::string::find_first_of() method.

http://www.cplusplus.com/reference/string/string/find_first_of/
wow thanks a lot, this will simplify a lot the code.

thanks again.
Topic archived. No new replies allowed.