Ignoring !numbers from the input stream

Hey everyone,

Is there a way to ignore anything that is not a number from the input stream?

Thanks
cout<<"Please enter numbers only.\n";

u could try a throw catch block i think
lol

I'll look into the throw catch block.

Thanks Aramil
i dont know if that will work i havent really looked into type conversion. i no that theres a better way to do it. ill look tomorrow
Wow, thanks a lot. I'll continue to look for an answer for a bit before I pass out. If I find one, ill post it to this thread.

found this you would just have to take input as a string
1
2
3
4
5
6
bool is_number(const std::string& s)
{
    return !s.empty() && std::find_if(s.begin(), 
        s.end(), [](char c) { return std::isdigit(c); }) == s.end();
}
Wow a million thank you's!
Topic archived. No new replies allowed.