How to check if all strings in a vector have the same size in C++

1 Answer

0 votes
#include <iostream> 
#include <vector>
#include <algorithm>
 
using namespace std; 
   
int main() 
{ 
    vector<string> v = {"aaa", "bbb", "ccc", "ddd", "eee", "fff"};
 
    bool b = all_of(v.begin(), v.end(), [](const string & s) {
                          return s.size() == 3;
                     });
    cout << b;
     
    return 0; 
} 
 
 
 
/*
run:
 
1
 
*/

 



answered Feb 6, 2020 by avibootz
edited Feb 7, 2020 by avibootz

Related questions

1 answer 227 views
1 answer 114 views
1 answer 116 views
1 answer 119 views
2 answers 217 views
...