Question

You are writing a program in C++. Give the necessary statements to open a file and...

You are writing a program in C++. Give the necessary statements to open a file and to confirm that the file has been successfully opened for writing.

Homework Answers

Answer #1

Code:
#include <iostream>
#include <stdio.h>
#include <fstream>

using namespace std;

int main()
{   //creating object of class ofstream
   ofstream writeFile;
   //opening the file named "file.txt" with object's function open()
   writeFile.open("file.txt");
  
   //checking whether file is opened or not using is_open() function
   //if file is opened, it returns 1 else 0
   //if file is opened, displaying a message
   if(writeFile.is_open())
   {
       cout<<"File has been successfully opened for writing\n";
   }  
   //closing the file
   writeFile.close();
  
   return 0;
}

Code Photo:
Output:

Know the answer?
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
Similar Questions
Writing a program in Python that reads a text file and organizes the words in the...
Writing a program in Python that reads a text file and organizes the words in the file into a list without repeating words and in all lowercase. Here is what I have #This program takes a user input file name and returns each word in a list #and how many different words are in the program. while True:   #While loop to loop program     words = 0     #list1 = ['Programmers','add','an','operating','system','and','set','of','applications','to','the','hardware',          # 'we','end','up','with','a','Personal','Digital','Assistant','that','is','quite','helpful','capable',           #'helping','us','do','many','different','things']        try:        ...
C++. This program can open a text file and print its contents to the screen. For...
C++. This program can open a text file and print its contents to the screen. For example, it could load the output.txt file generated in the previous program and display on the screen the text contained in the file.
C++ Xcode (mac) This program can open a text file and print its contents to the...
C++ Xcode (mac) This program can open a text file and print its contents to the screen.For example, it could load the output.txt file generated in the previous program and display on the screen the textcontained in the file.
Goals: Write a program that uses binary files. Write a program that stores records to a...
Goals: Write a program that uses binary files. Write a program that stores records to a binary file. C++ Requirements: Write a program that includes a structure named Part that contains the following fields: name - a character array of 20 elements that stores the name of the part. qty - an integer that stores the number of parts in stock. price - a double that stores the price of the part. Create three Part variables in main, and fill...
You are to write a C program that will read from a file, one or more...
You are to write a C program that will read from a file, one or more sets of x,y coordinates. Each set of coordinates is part of a Cartesian system. A Cartesian coordinate system is a system that specifies each point uniquely in a plane by a pair of numerical coordinates. Your program will determine which quadrant each set belong. - Quadrants are often numbered 1st - 4th and denoted by Roman numerals: I(+,+), II (−,+), III (−,−), and IV...
C# Reading from Files Write a program to open a text file containing information about buildings....
C# Reading from Files Write a program to open a text file containing information about buildings. The program must display all the buildings in the file and then find the lowest cost building based on the cost per square foot. Format for one building: <building name> <size> sqft $<cost> Example: Allgood Hall 35000 sqft $8,250,099.75 Create the text file and add three or more of your favorite buildings.
C# Reading from Files Write a program to open a text file containing information about buildings....
C# Reading from Files Write a program to open a text file containing information about buildings. The program must display all the buildings in the file and then find the lowest cost building based on the cost per square foot. Format for one building: <building name> <size> sqft $<cost> Example: Allgood Hall 35000 sqft $8,250,099.75 Create the text file and add three or more of your favorite buildings.
Q.6) What does it mean if you compile your C# source code file and you only...
Q.6) What does it mean if you compile your C# source code file and you only get copyright information about Microsoft as a response? a) You have not set the path to the compiler correctly. b) Your program has syntax errors that you must correct before you can compile the program. c) The compiler cannot find the source code file that you are trying to compile. d) The compiler successfully compiled your program. Q.4) To compile a C# source code...
Create a program that filters the data in a CSV file of product data based on...
Create a program that filters the data in a CSV file of product data based on some search word and prints the resulting output to a new file. Additionally, the program will print the number of items filtered to stdout. • Your program should take three arguments: an input file to process, an output file to save the results, and a search word. • If the output file already exists or cannot be opened, warn the user by printing "CANNOT...
Code a C file, following these instructions: This lab is about getting the input from a...
Code a C file, following these instructions: This lab is about getting the input from a file. Let’s assume the words are provided in one file, passed as an argument to your program. The names of the files are provided as arguments to your program (i.e., they are copied by the shell in the argv variable), and each file is a text file with lots of words. Open the manual page for open() system call and add to your code...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT