1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Olin [163]
3 years ago
8

Write C++ code to open a document with the name Hello.txt, place the message "Hello, World!" in the document, and exit the docum

ent. Re open the file you closed, and read the message into a string variable. Exit out of the file.
Computers and Technology
1 answer:
gavmur [86]3 years ago
5 0

Answer:

#include<iostream>

#include<fstream>

using namespace std;

int main()

{

ofstream out;

out.open("Hello.txt");

out << "Hello, World!"<< endl;

out.close();

ifstream in;

in.open("Hello.txt");

while(in.good()){

   string line;

   in >> line;

   cout << line << endl;

   

}

in.close();

return 0;

}

Explanation:

Step 1:

Add all your preprocessor files directive,  #include is known as the preprocessor  is used to load files needed to run the code.

#include<iostream>: it provides basic input and output services for C++ programs.

#include<fstream>:used to open a file for writing and reading

using namespace std; means you'll be using namespace std means that you are going to use classes or functions (if any) from "std" namespace

Step 2:

ofstream out; <em>his  is  used  to  create  files  and   write data to the file</em>

out.open("Hello.txt"); <em>  a new file "HELLO.txt" has been created</em>

out << "Hello, World!"<< endl;  "<em>Hello World!" has now been writen to the file</em>

out.close(); <em>The file is now closed</em>

<em>This second step opens a new file and writes hello world to the file then closes it.</em>

Step 3:

<em>ifstream in; ifstream in c++ is a stream class which stands for input file stream a  is used for reading data from file.</em>

in.open("Hello.txt"); <em>Reopens the file without recreating it. This is a very important step because if not done properly, you might discard the file you previously created and recreate it.</em>

while(in.good()){

<em> in.good() is true if the previous read operation succeeded without EOF being encountered</em>

   string line; <em>It declares a string variable line</em>

   in >> line; <em>reads the data into the line variable</em>

   cout << line << endl; <em>Prints out the line</em>

<em>reopens the file and read the message into a string variable "line".  prints out line then exits out of the file.</em>

You might be interested in
What is computer system<br>explain the role of bank in computer<br>​
vodomira [7]

Answer:

This is your answer please check this ✔

5 0
2 years ago
Read 2 more answers
As the team leader, John ensures that all his teammates are clear in the team goals they need to achieve. He demonstrates the qu
zimovet [89]

Delegation ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

7 0
3 years ago
Read 2 more answers
Digital signatures are as legally acceptable as written signatures.
Leto [7]

Answer:

First point and the last point are the correct answer to the given question .

Explanation:

The main objective of the digital signature is to ensure the quality of the document or the message was not changed during the transfer of message in the network.

Following are the advantages of the digital signature

  • As compare to the electronic signature the digital signature is more secure then that of.
  • The signer's signature is seen on the digital signatures as the physical proof.
  • Global recognition, and the compliance with the law.

All the other options are incorrect they are not advantage of the digital signature .

4 0
3 years ago
The World Health Organization decided that addiction to video games is considered a mental health disorder. Do you agree or disa
Blababa [14]

Answer:

I disagree and I will tell you why because there was study based on video games and seniors and the theory was that they play games to keep there minds active. I will give you an example let's say you were in a situation and you learned how to make or create something from playing video games, in closeur video games can help us in problems

8 0
3 years ago
Look at the data set below. {9, 12, 12, 15, 18, 20, 25} in this data set, what is the median
cluponka [151]

. Answer: Median: 15

8 0
3 years ago
Read 2 more answers
Other questions:
  • A company that hires only American Indians is practicing
    5·2 answers
  • Which of these are forms of data? Check all that apply.
    8·2 answers
  • Pick 2 different operating systems and discuss how they can be used in daily operations.
    5·1 answer
  • Your marketing director at ABC Marketing Agency would like to set up an email campaign that will use personalization to referenc
    5·1 answer
  • 3. When you right-click a linked spreadsheet object, what commands do you choose to activate the Excel features?
    7·2 answers
  • While troubleshooting a network connection problem for a coworker, you discover the computer is querying a nonexistent DNS serve
    13·1 answer
  • Question 3
    13·1 answer
  • Which type of document should Omar print?
    5·2 answers
  • Help please i will mark brainlist!
    7·1 answer
  • Use the ________ tag to configure a generic area on a web page that is embedded within a paragraph or other block display elemen
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!