Ok so I have the easy part of this problem figured out but the other part is confusing me. Here's the problem:
Write a program that reads in a line of text and outputs the line with all the digits in all integer numbers replaced with 'x'.
Example
Input: My name is tony95 and my 5 digit zip is 89115
Output: My name is tony95 and my x digit zip is xxxxx
The problem I have is that ALL the digits are converted to x including 'tony95' becomes 'tonyxx'. I need only the integer numbers to be converted not the combined char/int. Please help! Here's what I have so far:
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
int i;
string st1;
cout << "Now enter a line of text: ";
getline(cin, st1);
cout << endl;
for (i = 0; i <= st1.length( ); i++)
{
if (st1[i] >= '0' && st1[i] <= '9')
{
st1.at(i)='x';
}
}
cout << "\nNew string with numbers replaced with 'x': " << st1 << endl << endl;
return 0;
}