• Register
1 vote
88 views

Problem :

I am trying to find solution for following error
replace any space ' ' by '_' in 2-character string passcode. sample output for the given program:
6.9k points

1 Answer

0 votes

Solution :

For single character it is easier to use the std::replace algorithm:

std::replace(passCode.begin(), passCode.end(), ' ', '_');

If you can not use the algo header you can use your own replace function. 

It can be done with a simple loop:

template<typename Iterator, typename T>
void replace(Iterator begin, Iterator end, const T& old_val, const T& new_val)
{
    for (; begin != end; ++begin)
        if (*begin == old_val) *begin = new_val;
}
I followed above approch and my issue got ressolved.
36.1k points

Related questions

0 votes
2 answers 92 views
92 views
Problem : I have following question complete the method definition to output the hours given minutes. output for sample program: 3.5
asked Nov 12, 2019 peterlaw 6.9k points
0 votes
1 answer 407 views
407 views
Problem : I learning Python with the help of free online Python tutorial which wants me to write following Program: Create a temperature converter which will convert Fahrenheit values to Celsius and vice-versa using the following two formulas which relate the temperature f in Fahrenheit to ... ,sep ='') if inputString[-1] == 'F': farenheit = inputDigit print(celsiusConvert(farenheit),'C', sep='')
asked Nov 21, 2019 peterlaw 6.9k points
1 vote
1 answer 228 views
228 views
Problem: I am new in python programming and I have been doing a course on it as a new comer I tried to repeat some char in a string. I wrote a code : def Work(str): for i in range(len(str)): return i * 2 But it does not work . how can I do this?
asked Apr 3 LizzyM 6.1k points