Reputation: 979
I am trying to test if accessing an element in a string is out of range. I know how to catch(std::out_of_range) but what im trying to do is if(out_of_range) Example:
string test;
int a;
test="123456789";
if(test.at(9)==out_of_range) //this isnt proper code but this is what im trying to accomplish
{
a=0;}
else
a=1;
I am programming in C++ VS10
Upvotes: 0
Views: 204
Reputation: 24269
The 'range' of a string is it's size. if there is 1 character in it, then it's size() is 1. So you could do
if(test.size() < 9)
Upvotes: 1