Question

In C, we use FILE *inFile = fopen(“input.txt”, “r”) to open a file to read from....

In C, we use FILE *inFile = fopen(“input.txt”, “r”) to open a file to read from. From the following choices, choose all of the correct ways of doing it in C++.

a. ifstream inFile(“input.txt”);
b. ifstream inFile;
   inFile(“input.txt”);
c. ifstream inFile;
   inFile.open(“input.txt”);
d. ifstream inFile = open(“input.txt”);

  

b

   

a

   

c

   

d

In C, we would use fclose(inFile) to close the previously opened input file. From the following choices, choose all of the correct ways of doing it in C++.

  

FILE.close(inFile);

   

inFile = close();

   

inFile.close();

   

close(inFile);

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student ,

As per requirement submitted above kindly find below solution.

Question :

Answer :

a.ifstream inFile("input.txt");

c. ifstream inFile;
inFile.open("input.txt");

Explanation :Above are the correct option to open the file in C++.Either use ifstream inFile("input.txt"); or use  inFile.open("input.txt");

**************************.

Question :

Answer :inFile.close();

Explanation :In C++ :inFile.close(); is used to close the file.

**************************

NOTE :PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
In C, we use FILE *inFile = fopen(“input.txt”, “r”) to open a file to read from....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Open read a text file “7NoInputFileResponse.txt” that contains a message “There were no arguments on the...

    Open read a text file “7NoInputFileResponse.txt” that contains a message “There were no arguments on the command line to be tested for file open.” Append to the program to output to the text log file a new line starting with day time date followed by the message "SUCCESSFUL". Append that message to a file “7Error_Log_File.txt” . ?newline Remember to be using fprintf using stderr using return using exit statements. Test for file existence, test 7NoInputFileResponse.txt file not null (if null...

  • Use two files for this lab: your C program file, and a separate text file containing...

    Use two files for this lab: your C program file, and a separate text file containing the integer data values to process. Use a while loop to read one data value each time until all values in the file have been read, and you should design your program so that your while loop can handle a file of any size. You may assume that there are no more than 50 data values in the file. Save each value read from...

  • MatLab Q) Use the file ‘xandypts.dat’ (bundled in the .zip file) whic contains x and y...

    MatLab Q) Use the file ‘xandypts.dat’ (bundled in the .zip file) whic contains x and y data points in the following format:                         x 0 y 1                         x 1.3 y 2.2 Write a script that will (1) use fopen to open the file and error-check to ensure it was opened; (2) use fscanf to read x and y; (3) compute the sum of x and the sum of y; (4) print out the sum of x and sum of...

  • The following program is in c++ ; I am trying to read in games from a...

    The following program is in c++ ; I am trying to read in games from a file and when doing so I am only reading in parts of the file. It is giving me a segmentation fault error I am going to post my code below if anyone is able to help me debug the program I would greatly appreciate it. The program is too large to be submitted as a single question on here :( --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- void Business::addGamesFromFile() {...

  • Validating Input file, So for my C++ assignment, my professor says we need to validate the...

    Validating Input file, So for my C++ assignment, my professor says we need to validate the Input File, Which means, if the line is missing a comma, one of the 3 information, or the string is a white line, it will ignore it. If the line has a white line, the program will correct it and will read in the line. I will store these into an Array, and display them in First name, Last name, and Number of Votes...

  • Theres an error on The bolded line, what am I doing wrong? #include <iostream> //just for...

    Theres an error on The bolded line, what am I doing wrong? #include <iostream> //just for writing and reading from console #include <fstream> //this one to deal with files, read and write to text files using namespace std; int main() { //first thing we need to read the data in the text file //let's assume we have the reading in a text file called data.txt //so, we need a stream input variable to hold this data ifstream infile; //now we...

  • For this assignment, you are to write a program that does the following:  read temperatures...

    For this assignment, you are to write a program that does the following:  read temperatures from a file name data.txt into an array, and  after reading all the temperatures, output the following to the monitor: the average temperature, the minimum temperature, and the total number of temperatures read. In addition, the program must use the following functions: //precondition: fileName is name of the file to open, inFile is the input file //postcondition: inFile is opened. If inFile cannot...

  • For this assignment, you are to write a program that does the following: • read exam scores from a file name data.txt into an array, and • after reading all the scores, output the following to the mon...

    For this assignment, you are to write a program that does the following: • read exam scores from a file name data.txt into an array, and • after reading all the scores, output the following to the monitor: the average score and the total number of scores. In addition, the program must use the following functions: //precondition: fileName is name of the file to open, inFile is the input file 2 of 2 //postcondition: inFile is opened. If inFile cannot...

  • For this assignment, you are to write a program that does the following: (C++) • read exam scores...

    For this assignment, you are to write a program that does the following: (C++) • read exam scores from a file name data.txt into an array, and • after reading all the scores, output the following to the monitor: the average score and the total number of scores. In addition, the program must use the following functions: //precondition: fileName is name of the file to open, inFile is the input file 2 of 2 //postcondition: inFile is opened. If inFile...

  • A. File I/O using C library functions File I/O in C is achieved using a file...

    A. File I/O using C library functions File I/O in C is achieved using a file pointer to access or modify files. Processing files in C is a four-step process: o Declare a file pointer. o Open the desired file using the pointer. o Read from or write to the file and finally, o Close the file. FILE is a structure defined in <stdio.h>. Files can be opened using the fopen() function. This function takes two arguments, the filename and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT