Comrades,
The following does not work:
vector<string>::iterator c;
for( c = holdtype.begin(); c != holdtype.end(); c++)
{
if( *c == "preposition" )
{
c++;
if( *c == "unknown" )
{
c++;
if( *c == "unknown" )
{
c++;
if( *c == "unknown" )
{
cout <<endl <<"This should be a verb " << *c;
}
}
}
}
}
The strange thing is that it works for a certain amount of data. As soon as it goes above roughly 30 words it stops working and gives me the “not dereferencable error”.
I have tried this and it gives the same results:
vector<string>::iterator c;
c = holdtype.begin();
while( c != holdtype.end())
{
if( *c == "preposition" )
{
if( c != holdtype.end() ) { c++; } else { break; }
if( *c == "unknown" )
{
if( c != holdtype.end() ) { c++; } else { break; }
if( *c == "unknown" )
{
if( c != holdtype.end() ) { c++; } else { break; }
if( *c == "unknown" )
{
cout <<endl <<"This should be a verb " << *c;
}
}
}
}
if( c == holdtype.end() ) { break; } else {c++;}
}
I have been trying to figure this out for a few days now, I am a beginner.
Your second version is almost correct, but you need to check if
cis valid after you increment and before you dereference: