Lecture02

Lecture02 - 3/20/10 1 CMPSC 24: Lecture 2 C C++ Transi9on...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 3/20/10 1 CMPSC 24: Lecture 2 C C++ Transi9on Divyakant Agrawal Department of Computer Science UC Santa Barbara Syllabus and other course informa9on hKp://www.cs.ucsb.edu/~agrawal/spring2010/ cmpsc24.html C++ Comments // This is a comment line x = x+1; // This is another comment 3/20/10 2 C++ Variable Ini9aliza9on int x(7), sum(); Add other examples in class. A Boolean Data Type bool cool = true; main must be declared int main int main() { return 0; } 3/20/10 3 Aside: Keyboard and Screen I/O #include <iostream> using namespace std; cin (of type istream) cout (of type ostream) Keyboard Screen execu%ng program input data output data <iostream> is header Fle for a library that deFnes 3 objects an istream object named cin (keyboard) an ostream object named cout (screen) an ostream object named cerr (screen) 9 Inser&on Operator ( << ) An output ( ostream ) operator that takes 2 operands The leE operand is a stream expression, such as cout The right operand is an expression describing what to insert into the output stream .g., cout << "The book costs" << cost; 3/20/10 4 10 Extrac&on Operator ( >> ) An input ( istream ) operator that takes 2 operands The leE operand is a stream expression, such as cin The right operand is a variable of simple type Operator >> aKempts to extract the next item from the input stream and store its value in the right operand variable .g., cin >> cost; The value being keyed in for cost must be the same type as that declared for variable cost 11 Whitespace characters Characters such as blanks, tabs, line feeds, form feed, carriage returns, and other characters that you cannot see on the screen xtrac9on operator >> skips leading whitespace characters before extrac9ng the input value from the stream Use func9on get to read the next character in...
View Full Document

Page1 / 11

Lecture02 - 3/20/10 1 CMPSC 24: Lecture 2 C C++ Transi9on...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online