Programming in C++ Giving a Value to a Variable In your program you can assign(give) a value to the variable by using the assignment operator ageOf。g=12; or by another method, such as cout < WHow old is your dog?; cin>> ageOf。g;
6 Giving a Value to a Variable In your program you can assign (give) a value to the variable by using the assignment operator = ageOfDog = 12; or by another method, such as cout << “How old is your dog?”; cin >> ageOfDog;
Programming in C++ Extraction Operator(>> so variable cin is predefined to denote an input stream from the standard input device( the keyboard) s the extraction operator > called get from" takes 2 operands. The left operand is a stream expression, such as cin--the right operand is a variable of simple type %operator > attempts to extract the next item from the input stream and store its value in the right operand variable
7 Extraction Operator ( >> ) ❖ variable cin is predefined to denote an input stream from the standard input device ( the keyboard ) ❖ the extraction operator >> called “get from” takes 2 operands. The left operand is a stream expression, such as cin--the right operand is a variable of simple type. ❖ operator >> attempts to extract the next item from the input stream and store its value in the right operand variable
Programming in C++ Extraction Operator >>(cont “ skips over (actually reads but does not store anywhere) leading white space characters as it reads your data from the input stream(either keyboard or disk file)
8 Extraction Operator >>(cont.) “skips over” (actually reads but does not store anywhere) leading white space characters as it reads your data from the input stream (either keyboard or disk file)
Programming in C++ Extraction Operator(cont) > is a binary operator > is called the input or extraction operator > is left associative EXPRESSION HAS VALUE cIn > age cIn STATEMENT cin > age > weight 9
9 Extraction Operator(cont.) >> is a binary operator >> is called the input or extraction operator >> is left associative EXPRESSION HAS VALUE cin >> age cin STATEMENT cin >> age >> weight ;
Programming in C++ Input Statements SYNTAX cin > Variable>> Variable.; These examples yield the same result cin > length cin > width cin > length > width 10
10 SYNTAX These examples yield the same result. cin >> length ; cin >> width ; cin >> length >> width ; Input Statements cin >> Variable >> Variable . . . ;