K
Ko van der Sloot
Hello
I was wondering which behaviour might be expected (or is required) for
the following small program.
I would expect that find( "a", string::npos ) would return string::npos
but is seems to be dependant on which string is searched for.
On my system, using gcc 4.1.2, I get:
pos1=2
problem because pos1=0
I expected this
#include <iostream>
#include <string>
using namespace std;
int main(){
string use = "anu";
string::size_type pos1 = use.find_first_not_of( "an" );
cerr << "pos1=" << pos1 << endl;
pos1 = use.find( "a", string::npos );
if ( pos1 == string::npos )
cerr << "I expected this" << endl;
else
cerr << "problem because pos1=" << pos1 << endl;
pos1 = use.find( "q", string::npos );
if ( pos1 == string::npos )
cerr << "I expected this" << endl;
else
cerr << "problem because pos1=" << pos1 << endl;
}
I was wondering which behaviour might be expected (or is required) for
the following small program.
I would expect that find( "a", string::npos ) would return string::npos
but is seems to be dependant on which string is searched for.
On my system, using gcc 4.1.2, I get:
pos1=2
problem because pos1=0
I expected this
#include <iostream>
#include <string>
using namespace std;
int main(){
string use = "anu";
string::size_type pos1 = use.find_first_not_of( "an" );
cerr << "pos1=" << pos1 << endl;
pos1 = use.find( "a", string::npos );
if ( pos1 == string::npos )
cerr << "I expected this" << endl;
else
cerr << "problem because pos1=" << pos1 << endl;
pos1 = use.find( "q", string::npos );
if ( pos1 == string::npos )
cerr << "I expected this" << endl;
else
cerr << "problem because pos1=" << pos1 << endl;
}