Sams Teach Yourself C++ in 21 Days
When the water (data) reaches the top, the valve opens and all the water flows out in a rush. Figure 17.3 illustrates this. 596 ...
Working with Streams 597 17 Streams and Buffers ................................................................................ ...
cin(pronounced “see-in”) handles input from the standard input, the keyboard. cout(pronounced “see-out”) handles output to the ...
Working with Streams 599 17 Input Using cin..................................................................................... ...
15: cout << “Long: “; 16: cin >> myLong; 17: cout << “Double: “; 18: cin >> myDouble; 19: cout << ...
Working with Streams 601 17 must have enough room in the buffer to allow for the entire string plus the null. The null signals t ...
LISTING17.3 Multiple Input 0: //Listing 17.3 - character strings and cin 1: 2: #include <iostream> 3: using namespace std; ...
Working with Streams 603 17 Int: 2 Long: 30303 Double: 393939397834 Float: 3.33 Word: Hello Unsigned: 85 Int: 2 Long: 30303 Doub ...
int varOne, varTwo, varThree; cout << “Enter three numbers: “ cin >> varOne >> varTwo >> varThree; When ...
Working with Streams 605 17 A common use of get()with no parameters is illustrated in Listing 17.4. LISTING17.4 Using get()with ...
This output is buffered until an end of line is read, however. When EOFis encountered (by pressing Ctrl+Z on a DOS machine, or C ...
Working with Streams 607 17 Getting Strings from Standard Input .............................................................. T ...
14: cout << “Enter string two: “; 15: cin >> stringTwo; 16: cout << “StringTwo: “ << stringTwo << ...
Working with Streams 609 17 13: cout << “stringOne: “ << stringOne << endl; 14: 15: cout << “Enter strin ...
Using cin.ignore()...................................................................................... At times, you want to i ...
Working with Streams 611 17 17: cout << “\n\nNow try again...\n”; 18: 19: cout << “Enter string one: “; 20: cin.get( ...
LISTING17.9 Using peek()and putback() 0: // Listing 17.9 - Using peek() and putback() 1: #include <iostream> 2: using name ...
Working with Streams 613 17 Outputting with cout................................................................................ ...
Line 6 is evaluated like this:std::cout.put(‘H’)writes the letter “H” to the screen and returns a coutobject. This leaves the fo ...
Working with Streams 615 17 One if by land One if by One if by land i?! OUTPUT The final line of output might look different on ...
«
27
28
29
30
31
32
33
34
35
36
»
Free download pdf