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.
#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!
Comments
Leave a comment