Cpp-Primer
Cpp-Primer copied to clipboard
ex8_13, the format function may throw out of range error
In ex8_13, the function format() use substr() but not check the string length,this may throw out of range error. I think we should add string length check in substr() function or in valid() function. And in valid() function , I think just check string first char is not correct enough. below is my improve. I check string length in valid() funciton
bool valid(const string& number)
{
if(number.size() < 7)
return false;
for(const auto i : number)
if(!isdigit(i))
return false;
return true;
}