Im fairly new to C and C++, having been learning for four months now.
I'm curious to know if I can parse an int to check for a non-digit character entered. I know I could use a string of char's and use !isdigit() for each char, but I just want to know if there is a similar way for int's?
#include <cstdlib>
#include <iostream>
#include <cctype>
typedefstruct
{
char name[20],email[50],phone[7];
long id;
}students;
/*function protos*/
void edit(students *vals);
int main(int argc, char *argv[])
{
students stu[40];
/*pointer to first array of struct*/
students *sptr = stu;
edit(sptr); //pass ptr to function
}
void edit(students *vals)
{
int record=0;
while(1)
{
cout << "\n\t\t" << "Enter the student id [numbers only]:\t";
cin >> vals[record].id;
if(vals[record].id ) /* what to put here? */
continue;
elsebreak;
}
}
"Parsing an int" has no meaning. An int is information that is already understandable by a computer (as opposed to, say, "1024").
After the cin, you already have an integral value in vals[record].id. There's no processing to be done.