A
Adrian
Why does std::strings find search from the begining of the string when
pos >= (std::string::npos-3)
I cant find anything in the standard that says what find should do if
pos==npos in find
I tried it on a few platforms (all with gcc unfortunaley) and its
seems to be consistent.
Adrian
Linux 64 bit:
g++=4.1.1
Flags=-Wall -ansi -pedantic
Result:
x=18446744073709551615 Found:a test
x=18446744073709551614 Found:a test
x=18446744073709551613 Found:a test
x=18446744073709551612 Not found
x=18446744073709551611 Not found
x=18446744073709551610 Not found
x=18446744073709551609 Not found
x=18446744073709551608 Not found
x=18446744073709551607 Not found
x=18446744073709551606 Not found
Linux 32 bit:
g++=4.1.1
Flags=-Wall -ansi -pedantic
Result:
x=4294967295 Found:a test
x=4294967294 Found:a test
x=4294967293 Found:a test
x=4294967292 Not found
x=4294967291 Not found
x=4294967290 Not found
x=4294967289 Not found
x=4294967288 Not found
x=4294967287 Not found
x=4294967286 Not found
Unixware 7.1.1
g++=2.95.2
Flags=-Wall -ansi -pedantic
Result:
x=4294967295 Found:a test
x=4294967294 Found:a test
x=4294967293 Found:a test
x=4294967292 Not found
x=4294967291 Not found
x=4294967290 Not found
x=4294967289 Not found
x=4294967288 Not found
x=4294967287 Not found
x=4294967286 Not found
FreeBSD 5.4
g++=4.1.2
Flags=-Wall -ansi -pedantic
Result:
x=4294967295 Found:a test
x=4294967294 Found:a test
x=4294967293 Found:a test
x=4294967292 Not found
x=4294967291 Not found
x=4294967290 Not found
x=4294967289 Not found
x=4294967288 Not found
x=4294967287 Not found
x=4294967286 Not found
Example Code:
#include <iostream>
#include <string>
#include <climits>
int main(int argc, char *argv[])
{
std::string a("this is a test");
std::string b("a t");
for(unsigned long x=ULONG_MAX; x>ULONG_MAX-10; --x)
{
std::string::size_type y=a.find(b, x);
if(y==std::string::npos)
{
std::cout << "x=" << x << " Not found\n";
}
else
{
std::cout << "x=" << x << " Found:" << a.substr(y) <<
std::endl;
}
}
return 0;
}
pos >= (std::string::npos-3)
I cant find anything in the standard that says what find should do if
pos==npos in find
I tried it on a few platforms (all with gcc unfortunaley) and its
seems to be consistent.
Adrian
Linux 64 bit:
g++=4.1.1
Flags=-Wall -ansi -pedantic
Result:
x=18446744073709551615 Found:a test
x=18446744073709551614 Found:a test
x=18446744073709551613 Found:a test
x=18446744073709551612 Not found
x=18446744073709551611 Not found
x=18446744073709551610 Not found
x=18446744073709551609 Not found
x=18446744073709551608 Not found
x=18446744073709551607 Not found
x=18446744073709551606 Not found
Linux 32 bit:
g++=4.1.1
Flags=-Wall -ansi -pedantic
Result:
x=4294967295 Found:a test
x=4294967294 Found:a test
x=4294967293 Found:a test
x=4294967292 Not found
x=4294967291 Not found
x=4294967290 Not found
x=4294967289 Not found
x=4294967288 Not found
x=4294967287 Not found
x=4294967286 Not found
Unixware 7.1.1
g++=2.95.2
Flags=-Wall -ansi -pedantic
Result:
x=4294967295 Found:a test
x=4294967294 Found:a test
x=4294967293 Found:a test
x=4294967292 Not found
x=4294967291 Not found
x=4294967290 Not found
x=4294967289 Not found
x=4294967288 Not found
x=4294967287 Not found
x=4294967286 Not found
FreeBSD 5.4
g++=4.1.2
Flags=-Wall -ansi -pedantic
Result:
x=4294967295 Found:a test
x=4294967294 Found:a test
x=4294967293 Found:a test
x=4294967292 Not found
x=4294967291 Not found
x=4294967290 Not found
x=4294967289 Not found
x=4294967288 Not found
x=4294967287 Not found
x=4294967286 Not found
Example Code:
#include <iostream>
#include <string>
#include <climits>
int main(int argc, char *argv[])
{
std::string a("this is a test");
std::string b("a t");
for(unsigned long x=ULONG_MAX; x>ULONG_MAX-10; --x)
{
std::string::size_type y=a.find(b, x);
if(y==std::string::npos)
{
std::cout << "x=" << x << " Not found\n";
}
else
{
std::cout << "x=" << x << " Found:" << a.substr(y) <<
std::endl;
}
}
return 0;
}