fork(1) download
  1. #include <iostream>
  2. #include <cstring>
  3. #include <string>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. int main() {
  8. constexpr auto doMatch = ".txt";
  9. constexpr auto doMatchSize = strlen(doMatch);
  10. constexpr auto doNotMatch = "_test";
  11. constexpr auto doNotMatchSize = strlen(doNotMatch) + doMatchSize;
  12. string input("somepath/testFile_test.txt");
  13.  
  14. if(input.size() >= doMatchSize &&
  15. equal(input.end() - doMatchSize, input.end(), doMatch) &&
  16. (input.size() < doNotMatchSize ||
  17. !equal(input.end() - doNotMatchSize, input.end() - doMatchSize, doNotMatch))){
  18. cout << "pass" << endl;
  19. }else{
  20. cout << "fail" << endl;
  21. }
  22.  
  23. return 0;
  24. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
pass