This class function CLASS::READWRITE is supposed to read data from an input file and write to an output file only if its input value is of type int. When I enter a floating point value is passed as x, the decimal places are truncated and the function executes normally instead of outputting a warning. If a lowercase letter like 'b' is passed as x, the value is apparently read as "0" so the function executes normally instead of outputting a warning.
How can I enforce the check (x != int)? I've seen suggestions for using cin.fail(), but I am not using cin here.
#include <iostream>
#include <fstream>
using namespace std;
ifstream input_file("in_file", ios::in);
ofstream output_file("out_file", ios::out);
int main(void)
{
CLASS object(n); // n is the number of values held in in_file
object.READWRITE(x); // x is some test value
}
void CLASS::READWRITE(int x)
{
int i;
for(i = 0; i < n; i++)
{
input_file >> number[i];
}
for(i = 0; i < n; i++)
{
if((x != int) || (x < 0))
{
out_file << "Error" << endl;
break;
}
else
{
out_file << num[i] << endl;
}
}
}