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
Community gardens are public gardens where local residents can grow plants in a plot. They are very popular, so there are often
Black_prince [1.1K]

Answer:

The information obtained is

  • Figure out who has been waiting the longest
  • Make a map of the waitlisted people

Explanation:

The information obtained from the combine data set is as follows

  • Figure out who has been waiting the longest
  • Make a map of the waitlisted people

The information from the waitlist database is combined thus the overall wait time of  the participants is estimated. Also the map of people around the globe is also made possible on the basis of the second database.

4 0
4 years ago
If you wanted readers to know a document was confidential, you could include a ____ behind the text stating
Maksim231197 [3]
I have no idea for that
4 0
3 years ago
Read 2 more answers
To add the word "confidential" to the background of a page, users would need to _____.
KengaRu [80]
I beleive you need to insert a watermark
3 0
3 years ago
16. (PPT) You can use features on the Video Tools Playback tab to adjust how and when the video plays during the slide
Nezavi [6.7K]

Answer:

a. True

Explanation:

5 0
2 years ago
Assume that you are testing the Orders database introduced in Watt (2014) - Appendix C. Discuss the problems and possible conseq
madreJ [45]

Answer:

129 \frac{2}{?} 23.4. \div 164 \times 5y1 + . \\ .00487ggh

6 0
3 years ago
Other questions:
  • As a graphic designer, you'll refer to a line as which of the following? A. Point B. Border C. Rule D. Frame
    9·2 answers
  • You are creating a database for your computer club. Most of the students live in your town, Durham. How can you make Durham appe
    11·1 answer
  • java A palindrome is a word or a phrase that is the same when read both forward and backward. Examples are: "bob," "sees," or "n
    5·1 answer
  • This is your code.
    9·1 answer
  • Complete the function to return the factorial of the parameter using recursion,
    10·2 answers
  • The Quick Access tool bar allows you to customize the actions or commands you frequently use.
    13·1 answer
  • What is computer forensics? Where and how would an IT auditor use thisresource?
    12·1 answer
  • Activity 8. Direction: Read the article and make an outline. Be guided by the rubric for outlining. Write your answer on a separ
    15·1 answer
  • What is a megavirus in computing
    8·2 answers
  • Project: Digital Media and Business
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!