finish the code segment below by selecting the statement that will open the input file specified (typed in) by the user: (more than one answer is possible) ifstream InFile; string filename; cout << "enter the name of the input file: "; cin >> filename; open.InFile(filename.c_str()); InFile.open(); InFile.open(filename.c_str()); InFile.open(filename); InFile.close(filename.c_str()); open.InFile(filename);
Added by Jose Manuel C.
Close
Step 1
The code snippet provided declares an `ifstream` object named `InFile` and a `string` variable named `filename`. It then prompts the user to enter a filename and reads it into the `filename` variable. Show more…
Show all steps
Your feedback will help us improve your experience
Audrey Fong and 69 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Audrey F.
The file has: 65 78 65 89 25 98 -999 87 34 89 99 26 78 64 34 -999 -999 23 99 98 97 26 78 100 63 87 23 -999 62 35 78 99 12 93 19 -999 C++ will not output correctly #include <iostream> #include <fstream> #include <iomanip> using namespace std; int main() { int sum; int num; int counter; ifstream infile; infile.open("Exp_5_24.txt"); counter = 0; infile >> num; while (infile) { sum = 0; sum = sum + num; infile >> num; while (num != -999) { sum = sum + num; infile >> num; } cout << "Line " << counter + 1 << ": Sum = " << sum << endl; counter++; infile >> num; } infile.close(); return 0; } Line 1: Sum = 420 Line 2: Sum = 511 Line 3: Sum = -305 Line 4: Sum = 398 This is what it is supposed to be: Line 1: Sum = 420 Line 2: Sum = 511 Line 3: Sum = 0 Line 4: Sum = 694 Line 5: Sum = 398
Akash M.
In C++, create a program that extracts and displays all vowels in a file. Prompt the user for the filename of a text file. Read through the entire file and write every vowel to the output file. Do not write consonants or spaces to the file. Write all line breaks (newlines) from the input file into the output file as well. The output filename should be similar to the input file. Use the input filename and preface the name with "vowels_". For example, if the input file is named foobar.txt, the output file should be named vowels_foobar.txt. Create all of this with a single filestream! You may not process more than one line of input before writing to the output file.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD