Oct 2, 2011 at 6:34am UTC
Chriscpp, your suggestion worked perfectly, thank you.
ne555, please read the question before posting; you obviously misunderstood.
Oct 2, 2011 at 6:41am UTC
I'm confused. I don't see how Chriscpp's answer has anything to do with your question, and ne555's answer seems to be directly on point.
EDIT:
Also I don't recommend this:
1 2
char filename[20];
cin >> filename; // if the user enters a string longer than 19 characters, you just corrupted memory
If you need a string, you're better off with a string:
1 2 3
string filename;
cin >> filename; // now a user can enter any length and you'll be OK
myfile.open(filename.c_str());
Last edited on Oct 2, 2011 at 6:43am UTC
Oct 2, 2011 at 2:43pm UTC
file << "abc" << endl << "xyz" ;
Oct 2, 2011 at 4:10pm UTC
Right. Or: file <<"abc\nxyz" ;
Oct 2, 2011 at 4:20pm UTC
So you can send an endl to a file.
ne555 should've said that in the first place.
Thanks all.
Oct 2, 2011 at 4:35pm UTC
Well I'm still just a beginner and the reference he posted only shows cout << endl;
Oct 2, 2011 at 7:19pm UTC
Mohammed Abdul don't edit your post to another question, post a new topic.It is confusing.