I'm trying to save everything to a .txt file with a new line after every string, but I can't get it to work for me. I tried using <<endl;
and "\n"
but it all gets written in a single line. So if I enter "John" for first
, "Smith" for last
, and "Casablanca" for film
, I get "JohnSmithCasablanca". I've gone through all my notes and my textbook. Am I doing something wrong?
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string first, last, film;
cout<<"Enter your first name and last name, then film(one word). ";
cin>>first;
cin>>last;
cin>>film;
ofstream outFile ("Customers.txt");
outFile<<film<<endl;
outFile<<first<<endl;
outFile<<last<<endl;
outFile.close();
return 0;
}