Checking function parameter data type in C++
<p>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.</p>

<p>How can I enforce the check (x != int)? I've seen suggestions for using cin.fail(), but I am not using cin here.</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;
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 &lt; n; i++)
    {
        input_file &gt;&gt; number[i];
    }

    for(i = 0; i &lt; n; i++)
    {
        if((x != int) || (x &lt; 0))
        {
            out_file &lt;&lt; "Error" &lt;&lt; endl;
            break;
        }
        else
        {
            out_file &lt;&lt; num[i] &lt;&lt; endl;
        }
    }
}
</code></pre>
