开发者

How do you use replace_if with a string?

开发者 https://www.devze.com 2023-03-03 12:22 出处:网络
I\'m trying to replace all whitespace characters in each line I\'m parsing with a space.The key line is:

I'm trying to replace all whitespace characters in each line I'm parsing with a space. The key line is:

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

The (partial) error I can locate is:

In 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]]’: instantiated from here

What is the correct usage of replace_if in this situation? I don't have access to Boos开发者_StackOverflowt, so I'd prefer pure C++ suggestions please. I've tried changing " " to string(" "). I've tried making my own predicate (I am a novice, so don't rule this solution out entirely). I'd prefer to use replace_if, but will accept an answer explaining why it is too complicated for this situation. Thanks.


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

replace_if( theString.begin(), theString.end(), ::isspace, ' ');
0

精彩评论

暂无评论...
验证码 换一张
取 消