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
How you use ict today and how will you use it tomorrow
kari74 [83]

Answer:

you use it in water today

Explanation:

tomorrow you'll use it in soda

6 0
2 years ago
What of the following google tools support collaboration
galben [10]

Answer:

Option(d) i.e All of the above is the correct answer to the given question.

Explanation:

In this question option are missing following are the options for this question (A)Docs

(B) Sheets

(C) Slides

(D) All of the Above

Google tools support collaboration is a type of cloud-based techniques such as docs ,sheet ,etc .It provides the guarantee to the designers who deliver around each other for the common goal it means the designers can develop the quicker also it can often to develop the sensible ones.

  • The Google tools support  collaboration such as docs of google encourages the openness because the employees in the various departments can see the each other's manuscripts.
  • All the option(A),option(B),option(C) are related to the google tools support collaboration that's why all these options are correct .
5 0
3 years ago
Select the two statements below that are true. Press on the info button for
bulgar [2K]

Answer:

The command print must be in lower case.

To show a variable or a number you do  not need quotation marks.

Explanation:

print("string here")

strings can be created with single or double quotes

print(3+5) returns 8

4 0
3 years ago
What is the diffrence between the the grassland and the savanna biomes
sergey [27]

Answer:

The term "savanna" is often used to refer to open grassland with some tree cover, while "grassland" refers to a grassy ecosystem with little or no tree cover.

Explanation:

5 0
3 years ago
Read 2 more answers
HELLO answer this. Sidney needs to create a decimal number variable that will be added to another number. What kind of variable
kipiarov [429]

Answer:

Option D. float is the correct answer.

Explanation:

Decimal number contains decimal point. Out of all the given data types, float data type store the number with decimal point.

As the number has to be further used for calculations float ahs to be used. Because the numbers can also be stored in string but cannot be used for further calculations.

Hence,

Option D. float is the correct answer.

8 0
3 years ago
Read 2 more answers
Other questions:
  • 1.
    13·1 answer
  • when you cross or enter traffic from a full stop, how much space should you allow on city streets? on the highway?
    11·1 answer
  • What does the do not disturb button do on the iphone?
    12·1 answer
  • As the operations manager for a supermarket chain, Mai needs to find a telecommunications technology that: enables managers in r
    9·1 answer
  • To support continuous improvement efforts in the workplace, you increase the number of tasks that an employee performs and have
    7·1 answer
  • Files with what two file extensions are commonly known as tarballs??
    8·1 answer
  • Loops are frequently used to ____; that is, to make sure it is meaningful and useful.
    12·1 answer
  • Suppose there are two hosts, S and R. They are communicating over a TCP connection, and R has already received from S al bytes f
    11·1 answer
  • Which of these is an example of collective voice?
    8·2 answers
  • Any action that causes harm to your computer is called a
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!