F
FBergemann
if i compile following sample:
#include <iostream>
#include <string>
int main(int argc, char **argv)
{
std::string test = "hallo9811111z";
std::string::size_type ret;
std::cout << "string is: <" << test << ">" << std::endl;
std::cout << "string.substr(5,3) is: <" << test.substr(5,3) <<
">" << std::endl;
std::cout << "1st check ->";
ret = test.substr(5,3).find_first_not_of("9876543210");
if (ret == std::string::npos){
std::cout << "is npos" << std::endl;
}
else {
std::cout << "is NOT npos, but <" << ret << ">" <<
std::endl;
}
std::cout << "2nd check ->";
ret = test.find_first_not_of("9876543210", 5, 3);
if (ret == std::string::npos){
std::cout << "is npos" << std::endl;
}
else {
std::cout << "is NOT npos, but <" << ret << ">" <<
std::endl;
}
}
the result is:
string is: <hallo9811111z>
string.substr(5,3) is: <981>
1st check ->is npos
2nd check ->is NOT npos, but <7>
I wonder, why 2nd check doesn't result in string::npos as well.
The manpage of fin_first_not_of() says:
"... returns the index of the first character within the current string
that does not match any character in str, beginning the search at index
and searching at most num characters, string::npos if nothing is found.
...."
???
Regards!
Frank
#include <iostream>
#include <string>
int main(int argc, char **argv)
{
std::string test = "hallo9811111z";
std::string::size_type ret;
std::cout << "string is: <" << test << ">" << std::endl;
std::cout << "string.substr(5,3) is: <" << test.substr(5,3) <<
">" << std::endl;
std::cout << "1st check ->";
ret = test.substr(5,3).find_first_not_of("9876543210");
if (ret == std::string::npos){
std::cout << "is npos" << std::endl;
}
else {
std::cout << "is NOT npos, but <" << ret << ">" <<
std::endl;
}
std::cout << "2nd check ->";
ret = test.find_first_not_of("9876543210", 5, 3);
if (ret == std::string::npos){
std::cout << "is npos" << std::endl;
}
else {
std::cout << "is NOT npos, but <" << ret << ">" <<
std::endl;
}
}
the result is:
string is: <hallo9811111z>
string.substr(5,3) is: <981>
1st check ->is npos
2nd check ->is NOT npos, but <7>
I wonder, why 2nd check doesn't result in string::npos as well.
The manpage of fin_first_not_of() says:
"... returns the index of the first character within the current string
that does not match any character in str, beginning the search at index
and searching at most num characters, string::npos if nothing is found.
...."
???
Regards!
Frank