Click here to Skip to main content
16,005,060 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generalchecking the type of an input in C++ Pin
Anonymous9-Feb-04 8:34
Anonymous9-Feb-04 8:34 
GeneralRe: checking the type of an input in C++ Pin
Maximilien9-Feb-04 8:52
Maximilien9-Feb-04 8:52 
GeneralRe: checking the type of an input in C++ Pin
David Crow9-Feb-04 8:55
David Crow9-Feb-04 8:55 
GeneralRe: checking the type of an input in C++ Pin
Maximilien9-Feb-04 9:01
Maximilien9-Feb-04 9:01 
GeneralRe: checking the type of an input in C++ Pin
David Crow9-Feb-04 8:53
David Crow9-Feb-04 8:53 
GeneralRe: checking the type of an input in C++ Pin
Garth J Lancaster9-Feb-04 10:35
professionalGarth J Lancaster9-Feb-04 10:35 
GeneralRe: checking the type of an input in C++ Pin
antlers9-Feb-04 11:28
antlers9-Feb-04 11:28 
GeneralRe: checking the type of an input in C++ Pin
John Carson10-Feb-04 4:06
John Carson10-Feb-04 4:06 
Anonymous wrote:
I have a function that accepts an input from the console and I need to check that the type of the value received is 'int' before attempting some computation on it.

1) Does anybody know how to do that ?


That depends on how you are reading it. If you use

int x;

std::cin >> x;

then a simple way to test for failure is with

if(std::cin)

after the read operation. This will return true if all went well and false if it didn't.

Because there are different failure conditions, there are different flags that can be set following failure and there are different functions for checking on them. If you want this level of detail, then it isn't simple because the same flag can be set in response to more than one type of failure and because there is not a one to one mapping between flags and the functions for retrieving them.

If there is a read failure, then you need to reset the input stream (using cin.clear()) so that reading can continue. You also need to tell cin to ignore the erroneous input with cin.ignore(...). I suggest you consult a good C++ book that covers IO Streams.

Anonymous wrote:
I desperately tried to find the answer in Visual Studio documentation but have drowned in the sea of documentation offered... is there any clear language reference supplied with the tool, organised in such a way you can actually find something in it ?

Unless you already know what you are looking for, you are unlikely to find it. Get yourself several good C++ books plus The C++ Standard Library by Nicolai Josuttis.

John Carson

"I wish to propose for the reader's favourable consideration a doctrine which may, I fear, appear wildly paradoxical and subversive. The doctrine in question is this: that it is undesirable to believe a proposition when there is no ground whatever for supposing it true."
- Bertrand Russell

GeneralHelp with Using HTMLHelp Topic Templates Pin
ElizabethC9-Feb-04 8:12
ElizabethC9-Feb-04 8:12 
QuestionHow to return an IPICTURE handle to VB from VC++ Pin
SNathani9-Feb-04 7:55
SNathani9-Feb-04 7:55 
AnswerRe: How to return an IPICTURE handle to VB from VC++ Pin
Ivor S. Sargoytchev9-Feb-04 11:46
Ivor S. Sargoytchev9-Feb-04 11:46 
GeneralGetting a controls handle Pin
Member 8709229-Feb-04 7:16
Member 8709229-Feb-04 7:16 
GeneralA DIBSection wrapper for Win32 and WinCE Pin
maxsrussell9-Feb-04 6:31
maxsrussell9-Feb-04 6:31 
GeneralRe: A DIBSection wrapper for Win32 and WinCE Pin
CodeBrain9-Feb-04 21:17
CodeBrain9-Feb-04 21:17 
GeneralRe: A DIBSection wrapper for Win32 and WinCE Pin
10-Feb-04 6:06
suss10-Feb-04 6:06 
GeneralCopy files Pin
rasha20039-Feb-04 5:54
rasha20039-Feb-04 5:54 
GeneralRe: Copy files Pin
Steve S9-Feb-04 7:10
Steve S9-Feb-04 7:10 
GeneralRe: Copy files Pin
rasha200310-Feb-04 3:52
rasha200310-Feb-04 3:52 
GeneralRe: Copy files Pin
David Crow9-Feb-04 8:04
David Crow9-Feb-04 8:04 
GeneralDynamic DataGrid problem Pin
bilas9-Feb-04 5:49
bilas9-Feb-04 5:49 
Generalhelp ambiguous call to overloaded function Pin
jackalwisdom9-Feb-04 4:55
jackalwisdom9-Feb-04 4:55 
GeneralRe: help ambiguous call to overloaded function Pin
David Crow9-Feb-04 5:24
David Crow9-Feb-04 5:24 
GeneralRe: help ambiguous call to overloaded function Pin
jackalwisdom9-Feb-04 13:45
jackalwisdom9-Feb-04 13:45 
GeneralRe: help ambiguous call to overloaded function Pin
David Crow10-Feb-04 3:09
David Crow10-Feb-04 3:09 
GeneralRe: help ambiguous call to overloaded function Pin
jackalwisdom10-Feb-04 3:39
jackalwisdom10-Feb-04 3:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.