Test: AP Computer Science A



Consider the following C++ code:


1. #include <iostream>

2. #include <fstream>

3. using namespace std;

4. int main() {

5.      ifstream outputFile;

6.      inputFile.open("TestFile.txt");

7.      outputFile << "I am writing to a file right now." << endl;

8.      outputFile.close();

9.      //outputFile << "I'm writting on the file again" << endl;

10.      return 0;

11. }


What is wrong with the code?

The outputFile should be of type "ofstream", not "ifstream".

The ifstream library should be included.

There is nothing wrong with the code.

Testfile.txt shouldn't have double quotations around it.

1/12 questions


Access results and powerful study features!

Take 15 seconds to create an account.
Start now! Create your free account and get access to features like:
  • Full length diagnostic tests
  • Invite your friends
  • Access hundreds of practice tests
  • Monitor your progress over time
  • Manage your tests and results
  • Monitor the progress of your class & students
By clicking Create Account you agree that you are at least 13 years old and you agree to the Varsity Tutors LLC Terms of Use and Privacy Policy.
Learning Tools by Varsity Tutors