Replacing tokens in a text file with replaced text
Its a little heavy on the code side.

Your definition of a token still leaves possibilities that you have not defined.

$$          :  Replace with $                                         Fine
$(&lt;X&gt;)      :  Replace with the mapped `&lt;X&gt;`                          Fine.

$(&lt;stuff&gt;\n : No closing ')'                                          Error
$()         : What happens with no identifier.                        Error
$&lt;X&gt;        : Some other character after '$' that is not '(' or '$'   Error


Especially your stream handling.
Its usually bad practice to test for .good(), .bad() or .eof() during normal processing. You want to test these after things go wrong to generate the appropriate error message or not. Usually stream code looks like this:

while(std::getline(stream, line))
{
    // correctly read a line
}

// or

while(stream &gt;&gt; value &gt;&gt; value2 &gt;&gt; value3 &gt;&gt; etc)
{
    // correctly read a value from the stream
}


You can use OO to compartmentalize your mapping.
Personally I would combine your mapper and mapped class into a single class.

class Mapper
{
    // Class contains a map from tokens =&gt; value
    // used via replace() to replace all tokens $(&lt;X&gt;) in string
    // with the values contained in the map.

    std::map&lt;std::string, std::string&gt;  replaceMap;
    public:
        Mapper(std::string const&amp; fileName)
        {
            // Read all the mapping values from the file.

            std::ifstream   mapFile(fileName.c_str());
            std::string     line;

            while(std::getline(mapFile, line))
            {
                // Each line in the file contains a token/value mapping
                std::stringstream   linestream(line);

                std::string         token;
                std::string         value;

                std::getline(linestream, token, ':');
                std::getline(linestream, value);

                // Save the token and value
                replaceMap[token]  = value;
            }
        }

        std::string replace(std::string const&amp; line)
        {
            std::string result;
            std::size_t last = 0;

            // Search for the '$' char repeatedly.
            for(std::size_t find = line.find('$');find != std::string::npos;last=find, find=line.find('$', find))
            {
                // Copy the inert text from line
                // into the result
                result  += line.substr(last, (find-last));

                // If the next character is a '(' then search for the closing ')'
                //
                // If we don't find a token `$(&lt;X&gt;)` then ignore the '$' and treat
                // it like a normal character. Note If &lt;X&gt; has no mapping then
                // we replace it with the empty string. Note if &lt;X&gt; is empty it is
                // is still value.

                bool hit = false 
                if ((find + 1 &lt; line.size()) &amp;&amp; line[find + 1] == '(')
                {
                    std::size_t end = line.find(')', find);
                    if (end != std::string::npos)
                    {
                        std::string key = line.substr(find+2, end-find-2);
                        result += replaceMap[key];
                        find = end + 1;
                        hit  = true;
                    }
                }

                if (!hit)
                {
                    // Token was not found.
                    // Put the '$' on the output and move on.
                    result  += '$';
                    find++;
                }
            }
            // Add the rest of the inert string to the output
            result  += line.substr(last);

            return result;
        }
};


This makes it easy to use:

int main(int argc, char* argv[])
{
    Mapper  mapper(argv[1]);

    std::ifstream   input(argv[2]);
    std::string     line;
    while(std::getline(input, line))
    {
        std::string result = mapper.replace(line);
        std::cout &lt;&lt; result &lt;&lt; "\n";
    }
}