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
Anyone trying to play?
Lunna [17]

Answer:

no

Explanation:

7 0
3 years ago
Read 2 more answers
How has 5G become more energy efficient?
photoshop1234 [79]

Option 4. The way that 5G is more efficient is that is is able to  utilize more energy efficient access points.

What is the 5G?

This is the term that is used to refer to the fifth generation mobile network. This is the latest generation of networks and it is known to be a faster way and a more efficient way of connecting to the internet when we compare it to the others that came before it.

This is known to have lower latency when we compare it to the 4G network. It is 100 times said to be faster than the 4G and more efficient for businesses and the people that use them. Hence the The way that 5G is more efficient is that is is able to  utilize more energy efficient access points.

Read more on 5G network here: brainly.com/question/24664177

#SPJ1

7 0
2 years ago
What does it NOT mean for something to be open source?
Readme [11.4K]

Answer:

Free to use but you have to pay a fee to modify

Explanation:

You NEVER have to pay for OPEN SOURCE

5 0
3 years ago
Given an array of integers check if it is possible to partition the array into some number of subsequences of length k each, suc
allochka39001 [22]

Answer:

Explanation:

Using Python as our programming language

code:

def partitionArray(A,k):

flag=0

if not A and k == 1:

return "Yes"

if k > len(A) or len(A)%len(A):

return "No"

flag+=1

cnt = {i:A.count(i) for i in A}

if len(A)//k < max(cnt.values()):

return "No"

flag+=1

if(flag==0):

return "Yes"

k=int(input("k= "))

n=int(input("n= "))

print("A= ")

A=list(map(int,input().split()))[:n]

print(partitionArray(A,k))

Code Screenshot:-

3 0
3 years ago
When are computers most vulnerable to threats or damage?
valentinak56 [21]
With virus protection
8 0
4 years ago
Other questions:
  • You try to enter your name into a cell that accepts a numeric value. What error would you receive
    12·2 answers
  • The ____ search feature allows you to look for words with extensions such as “ing,”“ed,” and so forth. .
    12·1 answer
  • What computer worm was used to sabatoge iran's nuclear program?
    11·1 answer
  • Many PC operating systems provide functionality that enables them to support the simultaneous execution of multiple applications
    13·1 answer
  • The birthday problem is as follows: given a group of n people in a room, what is the probability that two or more of them have t
    12·1 answer
  • Did you know you can buy a Passport Online?
    12·2 answers
  • I'm having trouble with an assignment of mine. I'm making a text based adventure game for extra credit in my class and I'm stuck
    12·1 answer
  • 45 points!!
    15·2 answers
  • What is the IT professional testing?
    15·1 answer
  • Javier downloads an illustration from an online Image library and modifies it for his purposes. The illustration he downloads is
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!