if statement

How do I use the cin >> function with the if statement?
First of all , you read about using cin. http://www.cplusplus.com/reference/iostream/cin/
Than, you read about using the if statement. http://www.intap.net/~drw/cpp/cpp04_02.htm
Than , you use cin (which by the way is an object, not a function) with the if statement.
operator>> is a function ;^)
Additional links:
http://www.cplusplus.com/doc/tutorial/basic_io/#cin
http://www.cplusplus.com/doc/tutorial/control/#if
http://www.cplusplus.com/articles/how_to_ask/

if ( cin >> variable ) will evaluate true when the input is read successfully ( if this is what you are asking )

//this is for single if statement

cin >> variable;
if (condition base on the input variable)

//the code to be executed if the condition is met

statement;


//for the multi if statement

cin>>variable;
if (condition base on the input variable)

{
//codes that are to be executed if the condition is met

statement 1;
statement 2;
statement 3;
statement 4;
}

Last edited on
Topic archived. No new replies allowed.