check to see if any number is assigned to a variable of type int

I need a to throw an exception if a has no value here is the code i have so far.
its on the seventh line with the ??marks.

istream& operator >>(istream& s, Rational& r)
{
int Tnum(0),Tdenom(0);
cout <<setw(20)<<" "<<"Please enter a fraction in this form N/D: ";
s >> r.temp;
string temp = r.temp;
int a = temp.find("/");
if(a==0||a!=???)
{
throw Rational::Alpha();
}
for (int i=0; i < temp.size();i++)
{
if (isdigit(temp.at(i)))
{
if (i<a)
{
istringstream strStream(temp.substr(i));
strStream>>r.num;
strStream.clear();

}
else
{
istringstream strStream(temp.substr(i));
strStream>>r.denom;
strStream.clear();

}
}
}



return s;
}
std::string::find() returns std::string::npos if nothing was found.
how do you implement that ? I cannot seem to get it to work
wait i figured it out. a is throwing a -1 if no pos is found from my int a=temp.find('/').
if found it throws a value of pos.
Last edited on
Topic archived. No new replies allowed.