Answer to Question #319705 in C++ for Eddy

Question #319705

Create a C++ program that will prompt the user for a line of text. This line of text must be written to a text file called info.txt

Once the line of text has been written, display a text on the screen alerting the user that information has been written to a file successfully.


1
Expert's answer
2022-03-28T11:00:22-0400
#include <iostream>
#include <fstream>
using namespace std;

int main () {
    string info;
    cout << "Please enter your info: ";
    cin >> info;
  ofstream myfile ("info.txt");
  if (myfile.is_open())
  {
    myfile << info;
    myfile.close();
    cout << "Your info has been stored!" << endl;
  }
  else cout << "Unable to open file\n";
 
 
  return 0;
}



Please enter your info: I am a man.
Your info has been stored!

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog