User input into a text file
Hello, I am somewhat new to C++ but one thing I can't seem to be able to figure out is how to have users inputed text into a text file using filestreams. I tried signing the users input to a string variable using cin and then putting into the text file. For example:
Code:
#include <iostream>
#include <fstream>
using namepace std;
int main()
{
string x;
cout << "Enter your name: ";
cin >> x;
ofstream a_file ("test.txt")
a_file << x;
return 0;
}
Can someone explain this to me please?