checking a string for a char
basically, i'm asking for a number of strips, and so this has to be an integer.
now what i have done is made it so that when u enter the number of strips, it saves it as a string in a file.
then it reads the file, twice, storing the value as a float and an integer and then checking that when you take one away from the other, it equals 0. This checks the value entered is an integer.
if you enter a character (first) it will again fail.
BUT
and this is my problem........ if i enter say 45h, it will work, using the number 45.
i would like to be able to make it bring up an error if there is a character within the string.
is this possible?
Code:
cout << "\nPlease input the number of strips required: ";
cin >> q;
ofstream prt ("strips.dat");
prt << q << endl;
ifstream read1 ("strips.dat");
read1 >> n1;
ifstream read2 ("strips.dat");
read2 >> n2;
n3 = n2 - n1;
while (!(n1) || n1 < 1 || n3 != 0 )
{
cin.clear();
textcolor(12);
cprintf ("The number of strips must be a positive integer.");
cout << "\nPlease try again: ";
cin >> q;
ofstream prt ("strips.dat");
prt << q << endl;
ifstream read1 ("strips.dat");
read1 >> n1;
ifstream read2 ("strips.dat");
read2 >> n2;
n3 = n2 - n1;
}