A
Adrian
Can this code ever throw out_of_range or should the commented out code
always be used?
Is there any chance that std::string::npos+1 is bigger then
std::string::npos
Take str to be any allowable string value.
#include <iostream>
#include <string>
int main(int argc, char *argv[])
{
std::string str;
str.erase(0, str.find_first_not_of(" \t"));
str.erase(str.find_last_not_of(" \t")+1, std::string::npos);
/*
str.erase(0, str.find_first_not_of(" \t"));
std::string::size_type x=str.find_last_not_of(" \t");
if(x!=std::string::npos)
{
str.erase(x+1, std::string::npos);
}
*/
return 0;
}
always be used?
Is there any chance that std::string::npos+1 is bigger then
std::string::npos
Take str to be any allowable string value.
#include <iostream>
#include <string>
int main(int argc, char *argv[])
{
std::string str;
str.erase(0, str.find_first_not_of(" \t"));
str.erase(str.find_last_not_of(" \t")+1, std::string::npos);
/*
str.erase(0, str.find_first_not_of(" \t"));
std::string::size_type x=str.find_last_not_of(" \t");
if(x!=std::string::npos)
{
str.erase(x+1, std::string::npos);
}
*/
return 0;
}