• Register
1 vote
189 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

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.
38.6k points

Related questions

0 votes
1 answer 10 views
10 views
Problem: What should I do if I can't find a solution anywhere : Complete the function to replace any period by an exclamation point?
asked Jun 18 Mezbah 130k points
0 votes
1 answer 2 views
2 views
Problem: Java how to replace a character in a string.
asked Jul 11 Rada Gracelynn 104k points
0 votes
1 answer 22 views
22 views
Problem: I have this string: ABCDEFGHIJ I need to replace from position 4 to position 5 with the string ZX It will look like this: ABCZXFGHIJ.
asked May 31 Irenka Kiri 85.5k points
0 votes
1 answer 15 views
15 views
Problem: Hey, i m asking you to teach me how to replace all the presence of string into javascript.
asked May 7 Ryan evans 1.6k points
0 votes
1 answer 16 views
16 views
Problem: Where should I seek assistance with this problem : The ____ method allows you to replace all occurrences of some character within a string?
asked Jun 12 Nahil 128k points
0 votes
1 answer 18 views
18 views
Problem: Python how to remove a character from string?
asked Jul 16 Sawyer Parviz 168k points
0 votes
1 answer 9 views
9 views
Problem : Unix command to replace a character in a file.
asked Jul 7 Isac Christiaan 103k points
0 votes
1 answer 7 views
7 views
Problem: \Remove all characters from string python.
asked Jul 19 akhi 125k points
0 votes
1 answer 8 views
8 views
Problem: Remove certain characters from string python
asked Jul 12 Hridoy 19.2k points
0 votes
1 answer 9 views
9 views
Problem: Replacing multiple characters in a string python
asked Jul 1 nila 121k points