• Register
1 vote
144 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 5 3
6,930 points

Please log in or register to answer this question.

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.
9 7 4
38,600 points

Related questions

0 votes
1 answer 4 views
4 views
Problem: Can anyone help me about this? If anyone know about loop to print each contact and contact email. Then please read my question carefully and answer me.
asked Mar 26 niyatiry 2.9k points
0 votes
1 answer 248 views
248 views
Convert seconds to hours, minutes and seconds #include <cstdio> #include <iostream> using namespace std; int main() {      int seconds, hours, minutes;      cin >> seconds;      hours = seconds/3600;      cout << seconds << "seconds is equivalent to" << ... know how to fix this? Whenever I do a number less than 3600, a message appears on the screen stating that the program has stopped working.
asked Aug 27, 2020 sasha 16.2k points
0 votes
1 answer 6 views
6 views
Problem: Can anyone help me about this? If yes, then please answer me.
asked Mar 26 niyatiry 2.9k points
0 votes
1 answer 48 views
48 views
Problem: I just started Bachelors in Software Engineering. Programming is the main subject of Software Engineering and I have no prior knowledge of programming. My programming teacher gave me an assignment in which I have to write a program in C++ whose output should be as ... a hint: Use nested loop. If someone knows how to do this kindly explain and provide me with the example program. Thanks.
asked Nov 29, 2020 Code Learner 9.2k points
0 votes
1 answer 3 views
3 views
Problem: Anyone here who know nested loops to print a rectangle. sample output for given program? If yes, then please answer me.
asked Mar 27 niyatiry 2.9k points
0 votes
1 answer 13 views
13 views
Problem: complete the method definition to output the hours given minutes. output for sample program:
asked Feb 23 Muneeb Saadii 125k points
0 votes
1 answer 30 views
30 views
Problem: assign total_owls with the sum of num_owls_a and num_owls_b. sample output for the given program:
asked Feb 23 Muneeb Saadii 125k points
0 votes
2 answers 1.6K views
1.6K 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 969 views
969 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