Reading a config file
<p>I'm trying to read a config file like this:</p>

<pre><code>rawfile=input.raw
encfile=encoded.enc
decfile=decoded.raw
width=512
height=512
rle=1
quantfile=matrix.txt 
logfile=log.txt
</code></pre>

<p>Having this function:</p>

<pre><code>void Compression::readConfigFile(char * input)
{
    string lineBuf;
    string optionBuf;
    std::ifstream confFile(input);

    if ( confFile.is_open() )
    {
        while ( getline( confFile, lineBuf ) )
        {
            optionBuf = "rawfile=";
            if ( ( ( int )lineBuf.find(optionBuf) ) != -1 )
            {
                lineBuf.erase( 0, optionBuf.length() );
                this-&gt;rawfile = lineBuf.c_str();
            }
            optionBuf = "encfile=";
            if ( ( ( int )lineBuf.find(optionBuf) ) != -1 )
            {
                lineBuf.erase( 0, optionBuf.length() );
                this-&gt;encfile = lineBuf.c_str();
            }
            optionBuf = "decfile=";
            if ( ( ( int )lineBuf.find(optionBuf) ) != -1 )
            {
                lineBuf.erase( 0, optionBuf.length() );
                this-&gt;encfile = lineBuf.c_str();
            }
            optionBuf = "width=";
            if ( ( ( int )lineBuf.find(optionBuf) ) != -1 )
            {
                lineBuf.erase( 0, optionBuf.length() );
                this-&gt;width = atoi( lineBuf.c_str() );
            }
            optionBuf = "height=";
            if ( ( ( int )lineBuf.find(optionBuf) ) != -1 )
            {
                lineBuf.erase( 0, optionBuf.length() );
                this-&gt;height = atoi( lineBuf.c_str() );
            }
            optionBuf = "rle=";
            if ( ( ( int )lineBuf.find(optionBuf) ) != -1 )
            {
                lineBuf.erase( 0, optionBuf.length() );
                this-&gt;rle = atoi( lineBuf.c_str() );
            }
            optionBuf = "quantfile=";
            if ( ( ( int )lineBuf.find(optionBuf) ) != -1 )
            {
                lineBuf.erase( 0, optionBuf.length());
                this-&gt;matrix = lineBuf.c_str();
            }
            optionBuf = "logfile=";
            if ( ( ( int )lineBuf.find(optionBuf) ) != -1 )
            {
                lineBuf.erase( 0, optionBuf.length() );
                this-&gt;logfile = lineBuf.c_str();
            }
            confFile.close();

        }
    }
    else
        cout &lt;&lt; "Can't open file: " &lt;&lt; input &lt;&lt; endl;
}
</code></pre>

<p>But it doesn't work. My ints are 0 or some big number. My strings are still empty.</p>

<p>Can someone help me please?</p>

<p>Kind regards,</p>
