0

次のような構成ファイルを読み込もうとしています:

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

この機能を持つ:

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->rawfile = lineBuf.c_str();
            }
            optionBuf = "encfile=";
            if ( ( ( int )lineBuf.find(optionBuf) ) != -1 )
            {
                lineBuf.erase( 0, optionBuf.length() );
                this->encfile = lineBuf.c_str();
            }
            optionBuf = "decfile=";
            if ( ( ( int )lineBuf.find(optionBuf) ) != -1 )
            {
                lineBuf.erase( 0, optionBuf.length() );
                this->encfile = lineBuf.c_str();
            }
            optionBuf = "width=";
            if ( ( ( int )lineBuf.find(optionBuf) ) != -1 )
            {
                lineBuf.erase( 0, optionBuf.length() );
                this->width = atoi( lineBuf.c_str() );
            }
            optionBuf = "height=";
            if ( ( ( int )lineBuf.find(optionBuf) ) != -1 )
            {
                lineBuf.erase( 0, optionBuf.length() );
                this->height = atoi( lineBuf.c_str() );
            }
            optionBuf = "rle=";
            if ( ( ( int )lineBuf.find(optionBuf) ) != -1 )
            {
                lineBuf.erase( 0, optionBuf.length() );
                this->rle = atoi( lineBuf.c_str() );
            }
            optionBuf = "quantfile=";
            if ( ( ( int )lineBuf.find(optionBuf) ) != -1 )
            {
                lineBuf.erase( 0, optionBuf.length());
                this->matrix = lineBuf.c_str();
            }
            optionBuf = "logfile=";
            if ( ( ( int )lineBuf.find(optionBuf) ) != -1 )
            {
                lineBuf.erase( 0, optionBuf.length() );
                this->logfile = lineBuf.c_str();
            }
            confFile.close();

        }
    }
    else
        cout << "Can't open file: " << input << endl;
}

しかし、うまくいきません。私のintは0または大きな数字です。私の文字列はまだ空です。

誰か助けてくれませんか?

敬具、

4

1 に答える 1

3

while ループの外側でファイルを閉じるべきではありませんか?

while() {
    ...
}
confFile.close();
于 2012-10-08T09:41:43.137 に答える