Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

To read information in from a file: which library do you have to include at the

ID: 3566244 • Letter: T

Question

To read information in from a file: which library do you have to include at the top of your program? The following will successfully open a filename provided by the user: It is only possible to open a file that is in the same directory as the program. If one tries to open a file for writing that does not exist, then a file of that name will be created. To write data at the end of an already existing file, called myFile.txt, one can open the file with which of the following? Write a section of code (not a full program) that will open a file called "data.txt" containing a series of integers for reading. Be sure to check that the file opened properly and print an error statement and exit the program if it did not. Then determine how many numbers are stored in the file and print out this result to the console (with cout). Be sure to close the file after you are done reading from it.

Explanation / Answer

Q1) fstream

Q2) False.. correct way of opening file is ifstream inFile(fName.c_str());

Q3) False. you can open any file any where by providing its proper path.

Q4) True.

Q5) outFile.open("myFile.txt", ios::app);

Q6)

ifstream infile("data.txt");
if(!infile){
cout <<"unable to open file so exiting from program " << endl;
return 0;
}
int count = 0;
while(!infile.eof()){
int value;
infile >> value;
count++;
}
infile.close();
cout <<"Total numbers in file are " << count << endl;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote