Sams Teach Yourself C++ in 21 Days
LISTING17.12 Adjusting the Width of Output 0: // Listing 17.12 - Adjusting the width of output 1: #include <iostream> 2: u ...
Working with Streams 617 17 LISTING17.13 Using fill() 0: // Listing 17.13 - fill() 1: 2: #include <iostream> 3: using name ...
ios::showpoint. TABLE17.1 shows some of the flags you can use. When using these flags, you need to include iostreamin your listi ...
Working with Streams 619 17 11: 12: cout.setf(ios::showbase); 13: cout << “The number is “ << hex << number &l ...
On line 16, the width is set to 10, and by default, the value is pushed to the extreme right. On line 20, the width is again set ...
Working with Streams 621 17 %l longinteger %ld double %f float Each of the conversion specifiers can also provide a width statem ...
hello world Hello again! 5 Here’s some values: 7 35 and also these: 98456 8.800000 Formatted: 7 35 8.800000 The first printf()st ...
Working with Streams 623 17 For example, cout << “\aAn error occured\t” rings the bell, prints an error message, and moves ...
open and close files, you create ifstreamand ofstreamobjects as described in the next few sections. Using the ofstream.......... ...
Working with Streams 625 17 One important file stream function that you will need right away is close(). Every file stream objec ...
On line 7, a buffer is created for the filename, and on line 8, another buffer is set aside for user input. The user is prompted ...
Working with Streams 627 17 6: { 7: char fileName[80]; 8: char buffer[255]; 9: cout << “Please reenter the file name: “; 1 ...
Please reenter the file name: test1 Current file contents: This line written directly to the file... This text is written to the ...
Working with Streams 629 17 Binary Versus Text Files ........................................................................... ...
19: long DaysAlive; 20: }; 21: 22: int main() // returns 1 on error 23: { 24: char fileName[80]; 25: 26: 27: cout << “Plea ...
Working with Streams 631 17 On lines 5–20, a stripped-down Animalclass is declared. On lines 24–34, a file is created and opened ...
LISTING17.19 Using Command-line Arguments 0: //Listing 17.19 Using Command-line Arguments 1: #include <iostream> 2: int ma ...
Working with Streams 633 17 LISTING17.20 Using Command-line Arguments To Get a Filename 0: //Listing 17.20 Using Command-line Ar ...
49: Animal BearTwo(1,1); 50: 51: cout << “BearTwo weight: “ << BearTwo.GetWeight() << endl; 52: cout << ...
Working with Streams 635 17 Four standard stream objects are created in every program:cout,cin,cerr, and clog. Each of these can ...
«
28
29
30
31
32
33
34
35
36
37
»
Free download pdf