string redactdigits Please help ThanX
Nov 21, 2015 at 10:57pm UTC
can you help write the code for this, I have no clue?
// replace digits with #'s
// e.g. redactDigits( "4 pizzas and 87 beers" )
returns "# pizzas and ## beers"
string redactDigits( const string & s );
the numbers should be different all the time
Nov 21, 2015 at 11:29pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <algorithm>
#include <iostream>
#include <string>
#include <cctype>
std::string redactDigits(const std::string& text)
{
std::string result(text);
std::replace_if(result.begin(), result.end(), std::isdigit, '#' );
return result;
}
int main()
{
std::cout << redactDigits("4 pizzas and 87 beers" ) << '\n' ;
}
Although, I suspect that's not the sort of implementation your instructor will be expecting.
Nov 21, 2015 at 11:34pm UTC
thanks for the replay but the code doesn't work
the numbers should change to #
Nov 21, 2015 at 11:40pm UTC
thanks for the replay but the code doesn't work
The code does work.
the numbers should change to #
The function returns a new string where the numbers are changed. Feel free to modify it to work on the original string if you'd like it to work that way.
Topic archived. No new replies allowed.