Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::count_if为什么不能统计char元素的个数? #1

Open
ender233 opened this issue Jun 27, 2017 · 0 comments
Open

std::count_if为什么不能统计char元素的个数? #1

ender233 opened this issue Jun 27, 2017 · 0 comments
Labels

Comments

@ender233
Copy link
Owner

ender233 commented Jun 27, 2017

问题来源:ID 165

     vector<char> v1{'1', '.', '1'};
     const char c = '1';
     int countNum = std::count_if(v1.begin(), v1.end(), c); 
     std::cout<<countNum<<std::endl;

报错信息:

/usr/include/c++/5/bits/stl_algo.h:3193:12:   required from ‘typename std::iterator_traits<_Iterator>::difference_type std::__count_if(_InputIterator, _InputIterator, _Predicate) [with _InputIterator = __gnu_cxx::__normal_iterator<char*, std::vector<char> >; _Predicate = __gnu_cxx::__ops::_Iter_pred<char>; typename std::iterator_traits<_Iterator>::difference_type = long int]’
/usr/include/c++/5/bits/stl_algo.h:3990:29:   required from ‘typename std::iterator_traits<_Iterator>::difference_type std::count_if(_IIter, _IIter, _Predicate) [with _IIter = __gnu_cxx::__normal_iterator<char*, std::vector<char> >; _Predicate = char; typename std::iterator_traits<_Iterator>::difference_type = long int]’
count_if.cpp:14:57:   required from here
/usr/include/c++/5/bits/predefined_ops.h:234:30: error: expression cannot be used as a function
  { return bool(_M_pred(*__it)); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant