Home Forums Gamescan Chat42 About
* Login   * Register * FAQ    * Search
It is currently Thu 11-20-2025 3:54PM

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: function to verify integer input in c++
PostPosted: Thu 02-17-2005 1:06AM 
Offline
Colonel
User avatar

Joined: Fri 08-22-2003 9:55AM
Posts: 960

Source: TJ North
I know there's one in Visual Basic, but is there a function to verify that input is actually an integer in Visual C++.

_________________
http://www.jestmag.com/3-5/banana.html


Top
 Profile  
    
 Post subject:
PostPosted: Thu 02-17-2005 7:35AM 
Offline
Major
User avatar

Joined: Tue 09-16-2003 7:23AM
Posts: 423
Location: Rolla

Source: TJ North
IsInt ( variable )

Returns 1 if true, 0 if not.


Top
 Profile  
    
 Post subject:
PostPosted: Thu 02-17-2005 7:49AM 
Offline
Brigadier General

Joined: Tue 01-22-2002 12:35PM
Posts: 1057
Location: Shawnee Mission, KS

Source: Off Campus
yashi wrote:
IsInt ( variable )

Returns 1 if true, 0 if not.


If he's trying to protect cin from getting slaughtered that's not going to help. If you try to cin an int and somebody puts a character string in there, cin will asplode.

Try this:

while (!cin>>IntegerVariable)
{
cout << "That's not an integer" << endl;
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
cout << "You entered the integer " << IntegerVariable << endl;

EDIT: If you're trying to "protect" an edit box in MFC, right click the edit box, go to the "Styles" tab and check "Number".


Top
 Profile E-mail  
    
 Post subject:
PostPosted: Thu 02-17-2005 12:39PM 
Offline
Colonel
User avatar

Joined: Fri 08-22-2003 9:55AM
Posts: 960

Source: TJ North
Awesome, thanks zKissane. It'd be helpful if we learned these things in class, but oh well.

_________________
http://www.jestmag.com/3-5/banana.html


Top
 Profile  
    
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group