Jan 18.primitive data and control structures

Jan 18.primitive - Last time we had looked at Quick review of last semester's topics to make sure we are all on the same page A first look at

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

View Full Document Right Arrow Icon
Last time, we had looked at: • Quick review of last semester’s topics to make sure we are all on the same page • A first look at differences between standard C++ and C++/CLI • An example (very, very simple) program that highlights some of those differences
Background image of page 1

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

View Full DocumentRight Arrow Icon
Simple I/O in Visual C++2005 Write and WriteLine – these two methods are used to display information on your screen Write writes the specified information to the standard output stream WriteLine writes the specified information followed by the current line terminator to the standard output stream the standard output stream is the console unless it has been set to something else by the SetOut method – to indicate that you want to output a string, prefix the string by an L. This tells the method that what you have is an C++/CLI string literal. WriteLine(L“This is the output”); Write(L“This is the output\n”); – the argument to these functions can be things other than strings -- more about this later, though. For now, we’ll deal with strings. Write and WriteLine are actually overloaded functions, and we’ve so far only dealt with two of those overloaded variations – the one that takes one string and the one that takes a string and a variable number of other objects following it.
Background image of page 2
Simple I/O in Visual C++2005 (cont.) Read and ReadLine – these two methods are used to get input from the standard input stream Read reads the next character from the standard input stream (not often used in C++) ReadLine reads the next line of characters from the standard input stream the standard input stream is the keyboard unless it has been set to something else by the SetIn method – to get input from the user, we usually use ReadLine a line is defined as a sequence of characters followed by a carriage return – the ReadLine method returns a sequence of characters, not an integer or a float or a double if you type 21 when prompted for your age, the ASCII character sequence 32 31 will be returned, NOT the binary value for the integer 21 (or 00000015H) Console::WriteLine(L“Please enter your age: ”); name = Console::ReadLine(); – important observation – the variable that is used to store the value returned by ReadLine must be a String ^ type unless you handle it as in the next example. String ^num1, //1st user input ^num2; //2nd user input
Background image of page 3

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

View Full DocumentRight Arrow Icon
// Using equality and relational operators #include “stdafx.h” using namespace System; int main() { int num1, num2; // two integers to be input by the user Console::Write (L”Please enter the first integer: “); num1 = Int32::Parse(Console::ReadLine() ); Console::Write (L”Please enter the second integer: “);
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/30/2008 for the course EE 361 taught by Professor Conry during the Spring '08 term at Clarkson University .

Page1 / 20

Jan 18.primitive - Last time we had looked at Quick review of last semester's topics to make sure we are all on the same page A first look at

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