#include <string>
#include <iostream>

std::string extract(const std::string& str, char beg, char end)
{
    std::size_t begPos ;
    if ( (begPos = str.find(beg)) != std::string::npos )
    {
        std::size_t endPos ;
        if ( (endPos = str.find(end, begPos)) != std::string::npos && endPos != begPos+1 )
            return str.substr(begPos+1, endPos-begPos-1) ;
    }

    return std::string() ;
}

int main()
{
    std::string original("This is the string of text $Iwantthis+notneeded text, end of the string.") ;
    std::cout << extract(original, '$', '+') << '\n' ;
}
