Originally Posted by
Daved
The replace function is a member function of the string class, so you should probably be calling it like you call find(). Then it's just a matter of putting in the right parameters.
Cheers mate, I got it working,
Code:
int i, pos;
string sen;
cout << "Please enter a sentence ";
getline (cin, sen);
char replace = 48;
string s2 = "?";
for (i = 0; i < sizeof(replace); i++)
{
while ((pos = sen.find(replace)) != string::npos)
{
sen.replace( pos, 1, s2 );
}
}
cout << sen;
But at the moment it can only get it to change one character, "0" if i wanted it to change 0,1,2,3,4,5,6,7,8,9
would i change
to (i know this doesn't work)
Code:
char replace = 48,49,50,51,52,53,54,55,56,57;
how do it do it? or would i have to copy that over and over again?