Error: E0254 type name not allowed

Asked

Viewed 358 times

0

I’m getting this error in this code:

bool Configuration::GetConfigBlockLine(ifstream& file, string& key, string& value)
{
    string line;

    // end of file
    while( !file.eof() )
    {
        // read line from config file
        getline( file, line );
        TrimString( line );

        // end of object's data 
        if( line.compare( "#end" ) == 0 )
            return false;

        size_t p = line.find( '=' );
        if( p != string.npos )
        {
            // key
            key = line.substr( 0, p );
            TrimString( key );

            // value
            value = line.substr( p + 1, line.length() );
            TrimString( value );

            // key - value pair read successfully
            return true;
        }
    }

    // error
    return false;
}

Apparently it says string is not an allowed name, in if( p != string.npos ) but why this error occurs and how can I fix it.

1 answer

3


The correct is "string::npos" and not "string.npos".

In the code fragment

size_t p = line.find('='); // linha 1
if (p != string::npos)     // linha 2

line 1 finds the position (index) of the character '=' inside the string "line"

in line 2, the comparison "p != string::npos" is true in the case of EXIST the character '=' inside the string "line".

  • Thank you! What’s this thing for?

  • ops, see new edition, with the corrected response

Browser other questions tagged

You are not signed in. Login or sign up in order to post.