Simple... TOO simple
I have built a very simple Parse class to detect whether a users input can be input into an integer variable or not. Here is the code:
Code:
#include <iostream>
using namespace std;
class inputParser
{
public:
bool IntParse(istream& _stream1, int& _int1)
{
_stream1 >> _int1;
if (_stream1.fail() || _stream1.bad())
return false;
else
return true;
}
};
int main()
{
int someInt;
inputParser Input;
cout << "Input an integer: ";
if (Input.IntParse(cin, someInt))
cout << "Is an integer";
else
cout << "Is NOT an integer";
system("pause");
return 0;
}
This code seems WAY too simple though, but it seems to work just fine... Am I missing something here or is this just how simple it should be?
R.I.P. 3.5" Floppy Drives
"I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein