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 the name of the domain controller database that windows server 2016 uses to store data about user access and resources o
Inessa05 [86]

The name of the domain controller database that Windows Server 2016 uses to store data about user access and resources on the network is Active Directory.

This Microsoft product manages permissions and access to networked resources. The main service in Active Directory is Domain Services (AD DS), which stores directory information and handles the interaction of the user with the domain.

3 0
3 years ago
ap csp The local, remote, and upstream _______ can each have multiple ___ _____. When a participant in a collaborative group on
ratelena [41]

Answer:

The Local, Remote and Upstream repository can each have multiple push /pull requests. When  a Participant in a collaborative group on Github is ready to have their work used by the group,  the participants makes a pull request.

Explanation:

These are simple blanks which are answer here

The Local, Remote and Upstream <u>repository</u> can each have multiple <u>push /pull</u> requests. When  a Participant in a collaborative group on Github is ready to have their work used by the group,  the participants makes a <u>pull request</u>.

8 0
3 years ago
Your friend decides to create a spreadsheet containing vocabulary terms and their definitions to help prepare for the unit test
Nataly_w [17]

Answer:

The answer is SORT

Explanation:

Just did the test :)

6 0
2 years ago
What does social protocol means in network?
Leokris [45]

Answer: a social protocol and something like DNS is that little socialbehavior, cues, or relationships are carried through DNS.

Explanation:

4 0
3 years ago
Hewo everyone look at me I look ugly don't I<br>​
Gwar [14]

Answer:

Na, you look stunning...!!!! UwU

4 0
3 years ago
Read 2 more answers
Other questions:
  • TRUE OR FALSE, databases allow you to search for content on the internet based on certain criteria (PLS ANSWER RIGHT)
    10·2 answers
  • 3. The invention of the transistor was important to the development of computers because it
    5·1 answer
  • For some reason, Danica's classmate George could not find the registered symbol in the symbol gallery. He is selling
    14·1 answer
  • Which of the following is the best example of an installation issue?
    6·2 answers
  • Caroline is building an expert system for wartime defense. Which of these is true about the system she is building?
    14·1 answer
  • The road is closed a head
    9·1 answer
  • Which of the following statements is TRUE of a peer-to-peer network?
    10·1 answer
  • Write steps for converting decimal to binary numbers?
    13·1 answer
  • Fill in the blanks with the correct words.
    7·1 answer
  • What are some legal issues that can arise from the use of social media?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!