How do you use replace_if with a string?

I am trying to replace all whitespace in each line where I parse the space. Key line:

replace_if( theString.begin(), theString.end(), ::isspace, " ");

I can find the (partial) error:

In the function 'void std :: replace_if (_ForwardIterator, _ForwardIterator, _Predicate, const _Tp &) [with _ForwardIterator = __gnu_cxx :: __ normal_iterator, std :: allocator →, _Predicate = int (*) (int) throw (), _Tp = char [2]]: created here

What is the correct use of replace_if in this situation? I do not have access to Boost, so I would prefer that there are suggestions in C ++. I tried changing "to a string (" "). I tried to make my own predicate (I am a beginner, so I do not exclude that this solution is complete). I would prefer to use replace_if, but I will accept the answer, explaining why it is too difficult for this situation . Thank.

+3
source share
1 answer

I think you want to use character space in single quotes. Strings are made up of characters, not strings.

replace_if( theString.begin(), theString.end(), ::isspace, ' ');
+4
source

All Articles