for and bool function problem
Oct 9, 2014 at 6:28pm UTC
I havn't touched code for a while now and dont know why "Success! (num)" dont print. Shouldn't "Success! 6 print?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
bool check_size(const string &s, string::size_type sz)
{
return s.size() >= sz;
}
int main()
{
string s = "Hello" ;
vector<int > nums = {1, 3, 5, 6, 1};
auto vecHasGreater = bind(check_size, s, _1);
for (auto beg = nums.begin(); !vecHasGreater(*beg); ++beg) {
cout << "Success! " << *beg << endl;
}
return -1;
}
Oct 9, 2014 at 7:10pm UTC
Do not forget that if at any point condition is false, loop stops executing.
your first element returns true from check_size function which is negated and so loop stops immideatly
Oct 9, 2014 at 7:17pm UTC
Oh that is what I forgot, thank you. Can`t believe I forgot that :/. Thank you :)
Topic archived. No new replies allowed.