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
Consider the eight bit signed binary number 1110 0101. Convert it to signed decimal from assuming the signed binary number is re
alukav5142 [94]

Answer:    -26

Explanation:

We have:  1 1 1 0   0 1 0 1

Since it’s one’s complement representation, then we check the very first digit to state if the number is negative or positive. Since the very first digit to the left is 1, then the number will be negative.

When it is negative, we now flip the bits, so that we get:

0 0 0 1   1 0 1 0

Notice we just turn the 1’s into 0’s and vice versa.

We now convert this binary into decimal:

We assign to each digit the corresponding power of 2.  

See it in a table:

\begin{matrix}0&0&0&1&1&0&1&0\\2^7&2^6&2^5&2^4&2^3&2^2&2^1&2^0 \end{matrix}

Then multiplying each digit by its corresponding power of 2 and then adding the results, we get:

2^4+2^3+2^1

We get:

16+8+2=26

Since we stated that the number is negative, then, the final result is: -26

4 0
3 years ago
Does any body know the name of this sensor? ​
kipiarov [429]

Answer:

ummm it looks like a fingerprint sensor

Explanation:

here a similar pic to it .i hope this helps :)

5 0
3 years ago
How to set up a paper format in any type of Microsoft version ????
Mashcka [7]
Explain further what you mean by that.
7 0
4 years ago
High quality pages in a task should all get the same Needs Met rating. For example, a high quality page for a common interpretat
marysya [2.9K]

Answer:

False

Explanation:

High quality page for a common interpretation always have different Needs Met rating than the high quality page for a minor interpretation of the query.

Although, both of this pages are of high quality we must differentiate the common from a minor interpretation of a query.

Needs Met should always know to place the high quality pages in a resolution hierarchy.

7 0
3 years ago
Most email clients contain a ____ that allows the user to read an email message without actually opening it
Stolb23 [73]
Most email clients contain a "subject" that allows the user to read an email message without actually opening it.
4 0
4 years ago
Read 2 more answers
Other questions:
  • The security administrator for PLABS.com recommends using a host-based firewall for all servers and workstations. What can a hos
    6·1 answer
  • What is the difference between operating systems and application software?
    6·2 answers
  • Most documents are printed in ______ orientation
    9·2 answers
  • What are the advantages of businesses using Twitter ?
    12·1 answer
  • How can the use of new technology in industry benefit the us government
    8·2 answers
  • Write a line of code to convert time to hours. Remember there are 60 minutes in an hour. Then write a line of code to calculate
    9·2 answers
  • Choose all items that represent characteristics of HTML attributes.
    5·2 answers
  • Give the uses of Word’s mail merge.
    8·1 answer
  • Evaluation of your strengths and weaknesses
    13·1 answer
  • What standards organization maintains the ethernet standard?.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!