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 a perfect hashing function?
antiseptic1488 [7]

Answer:

First we understand what is hash function.A hash function is mostly used in Hashmaps. It maps different keys to a set of values.There may occur a case when we have same key but different values.This case is called collision.So we have to use different collision handling techniques that are open addressing and separate chaining.

A perfect hash function maps key-value pair such that there are no collisions.

3 0
2 years ago
a uniform density sheet of metal is cut into a shape of an isosceles triangle, which is oriented with the base at the bottom and
Cloud [144]

The horizontal center of mass will be located at the horizontal center of mass will be located on the center line. This is further explained below.

<h3>What is Location?</h3>

Generally, a location or place that is inhabited, open for occupation or distinguished by some distinctive feature: situation The setting of the property contributes significantly to its overall allure.

In conclusion, The center line will serve as the location for the horizontal center of mass, which will be found at the same location as the center line.

Read more about Location

brainly.com/question/11718756

#SPJ1

6 0
2 years ago
The ACME Online Store offers different preferred customer discounts for customers who are "None", "Bronze", "Silver" and "Gold".
Nookie1986 [14]

Yes, the written program has the correct logic to assign the correct discount for each of the 4 valid values of customer_category

<h3>What is a Program?</h3>

This refers to the sequence of instructions that are keyed into a computer to execute user-specific commands.

Hence, we can see that based on the variable customer_category that has a string that is one of these 4 values:

0 for "None"

5 for "Bronze"

10 for "Silver"

20 for "Gold"

The program uses the correct syntax as it gives the correct discount based on the assigned values of the variable customer_category as executed with the syntax above.

Read more about programs here:

brainly.com/question/1538272

#SPJ1

8 0
2 years ago
A qualifier distinguishes the set of objects at the far end of the association based on the qualifier value.
Andrei [34K]

Answer:

True

Explanation: A qualifier is a term used in IT(information technology) and computer software. It is used to differentiate/ identify and select different sets of objects that are located at the far ends of a qualifier association.

A qualifier is usually used to identify an object from a set of closely related and similar objects, they are usually small boxes possibly with a rectangular shape.

7 0
2 years ago
Set-In-Order includes making changes to the layout of the area.A) TrueB) False
Bogdan [553]

Answer:

A) True

Explanation:

Set-In-Order is part of a 5S system approach of making a workplace to be well arranged so there will be smooth operation of employees and working conditions.

Set-In-Order specifically deals with entities in the workplace apparently labeled after being well arranged in their respective places.

Hence, it is TRUE that Set-In-Order includes making changes to the layout of the area.

7 0
3 years ago
Other questions:
  • Which step of creating a financial budget involves listing the payroll, rental, and utility costs?
    10·2 answers
  • Alex leads a team of eight members. Arrange his tasks in sequential order of phases of group dynamics. What are the stages in gr
    13·1 answer
  • Keyboard question: <br> How do I make the 'congruent to' symbol on this keyboard?
    8·1 answer
  • 2.1. The stream cipher described in Definition 2.1.1 can easily be generalized to work in alphabets other than the binary one. F
    10·1 answer
  • Respond to the following in a paragraph of no less than 125 words. Describe the steps to active listening.
    7·2 answers
  • The students of a college have to create their assignment reports using a word processing program. Some of the questions in thei
    9·1 answer
  • Waygate's residential Internet modem works well but is sensitive to power-line fluctuations. On average, this product hangs up a
    6·1 answer
  • How many different textile items would you find at a festival? (please list 5 items)
    7·1 answer
  • Question #2: How would you demonstrate professionalism in a video call with a teacher? Edmentum Digital world Please Help!!
    8·1 answer
  • How to tell if your phone is being monitored
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!