Changing characters in a string.
Hi, I’m trying to write a simple program to change the charters in a string, but for some reason I cant get it to work, and I cant for the life of me work out why, im fairly new to c++ so im sure must be doing some stupid mistake, but if someone could have a look at this code, and give me a pointer or 2, it would be greatly appreciated.
Basicly all i want it to do is change all the "x"'s to an upper case X...
it will change the first one, but thats it...
Code:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
string sen;
cout << "Please enter a sentence ";
getline (cin, sen);
string::size_type senx = sen.find( "x" );
if (senx >=0)
{
sen[senx] = toupper (sen[senx]);
string::size_type senx = sen.find( "x" );
}
cout << sen << endl;
system("PAUSE");
return EXIT_SUCCESS;
}