fork(1) download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <iterator>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9. const auto foo = "this (is(maybe)) a test (and maybe not)"s;
  10. const auto start = find(cbegin(foo), cend(foo), '(');
  11. const auto finish = find_if(start, cend(foo), [count = 0](const char i) mutable {
  12. if (i == '('){
  13. count++;
  14. }
  15. else if (i == ')'){
  16. count--;
  17. }
  18. return count <= 0; });
  19.  
  20. if(start == cend(foo)) {
  21. cout << "No '(' character found\n";
  22. } else if(finish == cend(foo)) {
  23. cout << "Even number of ')'s found\n";
  24. } else {
  25. cout << string(next(start), finish) << endl;
  26. }
  27. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
is(maybe)