175k views
1 vote
Given the availability of an ofstream object named output, and a string variable name tweet, write the other statements necessary to open a file named "mytweet", display the prompt tweet: and then read an entire line into tweet and then write it out to the file mytweet. (Do not define a main function.)

User Xab
by
5.4k points

1 Answer

6 votes

Answer:

The answer to this question can be given as:

code:

cout << "tweet:"; //print message.

getline(cin,tweet); //calling function getline.

output.open("mytweet"); //calling open by creating object of ofstream.

output << tweet;

output.close(); //close file.

Step-by-step explanation:

In the above c++ programming language code firstly we print the tweet variable as a message. Then we call the getline() function. In this function, we pass two variables that is cin and tweet. Then we create the object of the ofstream class that is output Then we open a file and call this file by output. In the next line, we use the output as a class function to print the value of the tweet variable. At the last, we close the file.

User Samanime
by
4.9k points