Click here to Skip to main content
15,886,014 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So I was running this code. GA Timetable which was originally running in 2008 but I run it in visual 2012. So I'm guessing there is some kind of a compatibility problem. So, below is the coding problem part.


C#
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;
}



error is here

c:\users\zahrina\documents\visual studio 2012\projects\gaschedule\gaschedule\algorithm\configuration.cpp(272): error C2275: 'std::string' : illegal use of this type as an expression
          c:\program files\microsoft visual studio 11.0\vc\include\xstring(2300) : see declaration of 'std::string'
c:\users\zahrina\documents\visual studio 2012\projects\gaschedule\gaschedule\algorithm\configuration.cpp(272): error C2228: left of '.npos' must have class/struct/union
Posted
Updated 22-Jun-14 20:44pm
v2
Comments
Peter_in_2780 23-Jun-14 2:55am    
Don't know for sure, but it looks like the line in question should have line.npos instead of string.npos
Member 10446157 23-Jun-14 5:00am    
thanks! :D

1 solution

Change string.npos to string::npos, see, for instance: std::string::npos att c++ reference[^].
 
Share this answer
 
Comments
Member 10446157 23-Jun-14 5:00am    
thanks! :D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900