Sign in to follow this  
gtgdgfdgfd

C++ console programming using cbuilder4

Recommended Posts

gtgdgfdgfd    122
I have a problem with C++ console programming using cbuilde4. I input data through overloaded operators of istream and write to a file through ofstream. Its working alright without validations. I have a problem of how to validate inputs of numeric fields and get back to the istream and write to the file. See below a part of code where I have tried this and relavent coding. If any body can help on this thats great. Thanks in advance. istream& operator>> (istream& instr, const Details& details){ details.inputData(instr); } stream& Details::inputData(istream& instr){ int keyval=0; cout << "ID Number : " << idNumber<<endl; cout << "Name : "; instr.ignore(); instr.getline(name,19); cout << "Address1 : "; instr.getline(address1,19); cout << "Address2 : "; instr.getline(address2,19); char *inputString; cout << "Postal Code : "; //validate numeric field postalCode ***************????? for (int i=0; i<8;i++){ keyval = getch(); if (keyval==13){ i=8;} cout<<(char)keyval; if(isdigit(keyval)) { inputString[i]==(char)keyval; } } *inputString >> postalCode ; //????problem is here cout <<endl<< "City : "; instr.ignore(); instr.getline(city,19); cout << "Fax No : "; instr >> fax ; instr.ignore(); return instr; }

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this