fork(1) download
  1. #include <string>
  2. #include <iostream>
  3.  
  4. std::string extract(const std::string& str, char beg, char end)
  5. {
  6. std::size_t begPos ;
  7. if ( (begPos = str.find(beg)) != std::string::npos )
  8. {
  9. std::size_t endPos ;
  10. if ( (endPos = str.find(end, begPos)) != std::string::npos && endPos != begPos+1 )
  11. return str.substr(begPos+1, endPos-begPos-1) ;
  12. }
  13.  
  14. return std::string() ;
  15. }
  16.  
  17. int main()
  18. {
  19. std::string original("This is the string of text $Iwantthis+notneeded text, end of the string.") ;
  20. std::cout << extract(original, '$', '+') << '\n' ;
  21. }
  22.  
Success #stdin #stdout 0s 3028KB
stdin
Standard input is empty
stdout
Iwantthis