Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C - C++ Learning > testing for err...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 15 Topic 4239 of 4370
Post > Topic >>

testing for error

by "Jeff Baker" <algorthjb@[EMAIL PROTECTED] > Aug 7, 2008 at 05:16 PM

Hi,

I am trying to test if a character gets into an integer field and found no

solution. Even just a single character has no way to test when the field
is 
an int.
Sample code:

#include <vector>
#include <iostream>
#include <conio.h>
class CInput
{
public:
  void Input();
  void Output();
private:
 std::vector<int>v;
 std::vector<int>::const_iterator it;
 int n;
};
void CInput::Input()
{ short ch = 13;
 do
 {
 std::cout << "Enter integer ";
 std::cin >> n;
 // WANT TO PUT A CONTINUE HERE BUT DON'T KNOW HOW TO TEST IF A CHARACTER 
GETS INTO n
 v.push_back(n);
 std::cout << "Enter to do another ";
 ch = getch();
 std::cin.ignore(2,'\n');
 std::cout << std::endl;
 }while(ch == 13);
}
void CInput::Output()
{
 for(it = v.begin();it != v.end(); it++)
  std::cout << (*it) << std::endl;
}
int main()
{
 CInput ob;
 ob.Input();
 ob.Output();
 return 0;
}

Jeff
 




 15 Posts in Topic:
testing for error
"Jeff Baker" &l  2008-08-07 17:16:07 
Re: testing for error
"Daniel T." <  2008-08-07 19:54:26 
Re: testing for error
Bart van Ingen Schenau &l  2008-08-09 11:37:37 
Re: testing for error
"Jeff Baker" &l  2008-08-13 19:04:00 
Re: testing for error
LR <lruss@[EMAIL PROTE  2008-08-14 21:40:18 
Re: testing for error
"Jeff Baker" &l  2008-08-15 05:34:50 
Re: testing for error
Keith Thompson <kst-u@  2008-08-15 12:29:56 
Re: testing for error
"Jeff Baker" &l  2008-08-15 18:09:47 
Re: testing for error
LR <lruss@[EMAIL PROTE  2008-08-15 18:25:26 
Re: testing for error
Ian Collins <ian-news@  2008-08-16 11:41:46 
Re: testing for error
LR <lruss@[EMAIL PROTE  2008-08-15 18:38:59 
Re: testing for error
"Jeff Baker" &l  2008-08-15 18:56:32 
Re: testing for error
LR <lruss@[EMAIL PROTE  2008-08-16 16:30:42 
Re: testing for error
"Jeff Baker" &l  2008-08-13 19:32:56 
Re: testing for error
Richard Heathfield <rj  2008-08-14 07:19:12 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 12:52:50 CST 2008.