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