SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
I/o Streams As An Introduction To Objects And Classes
Exercise:
Self-test Exercises
Question:2 | ISBN:9780321531346 | Edition: 7

Question

Suppose you are continuing to write the program discussed in the previous exercise and you want your program to take its input from the file stuff1.dat and send its output to the file stuff2.dat. What statements

do you need to place in your program in order to connect the stream fin

to the file stuff1.dat and to connect the stream fout to the file stuff2.dat? Be sure to include checks to make sure that the openings were successful.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

fin.open("stuff1.dat");

if (fin.fail( ))

{

cout << "Input file opening failed.\n";

exit(1);

}

fout.open("stuff2.dat");

if (fout.fail( ))

{

cout << "Output file opening failed.\n";

exit(1);

}

0 0

Discussions

Post the discussion to improve the above solution.