files-extra-practice - Extra File Practice This page...

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

View Full Document Right Arrow Icon
Extra File Practice This page provides a little more extra practice on some basic file ideas, mostly independent of other concepts. Try practice problems in Chapter 9 of Mercer for extra practice. Basic Output 1. Create a new program and add the proper header for file streams. 2. Declare and open in one line an output file object called outfile that creates the file test-file.txt . 3. Add this line of code to try file output: outfile << "Hello, File!" << endl; 4. Now close the file with this code: outfile.close(); 5. Now go locate the file on your computer and verify that output worked. (Look in your project directory or use the OS's search feature.) Opening Separately from Declaration 1. Change your program so that instead of declaring and opening the file object in the same line, you just declare it, i.e. ofstream outfile; 2. Then, on the next line, open the file: outfile.open("test-file.txt"); 3. Compile and run this program and verify that the behavior is the same. Same Game with Input and Mixing Input and Output
Background image of page 1

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

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

Page1 / 2

files-extra-practice - Extra File Practice This page...

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

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