|
-
Feb 2nd, 2003, 10:21 PM
#1
Thread Starter
Stuck in the 80s
[Resolved] File Writing Help
I have this function:
Code:
void addmovie() {
char string[50] = {'\0'};
ofstream outFile("C:\\test.txt", ios::out);
if (!outFile) {
cout << "File could not be opened!" << endl;
exit(0);
}
cout << "String: ";
cin.ignore();
cin.getline(string, 50, '\n');
//outFile.seekp(outFile.eof());
outFile << string;
outFile << '\n';
}
How can I make it output at the end of the file, rather than overwriting it?
I thought about reading the file, and adding to it, then writing it back...but is there any other way?
Last edited by The Hobo; Feb 3rd, 2003 at 11:59 AM.
-
Feb 2nd, 2003, 11:37 PM
#2
Code:
ofstream outFile("C:\\test.txt", ios:ut);
Instead of ios::out, try ios::app
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Feb 3rd, 2003, 09:43 AM
#3
Monday Morning Lunatic
I would suggest doing this:
Code:
string s;
getline(cin, s);
It's safer than your 50 character limit.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 3rd, 2003, 11:56 AM
#4
Thread Starter
Stuck in the 80s
Originally posted by parksie
I would suggest doing this:
Code:
string s;
getline(cin, s);
It's safer than your 50 character limit.
I would love to, however my teacher will not allow it.
crptcblade, I'll give it a try.
-
Feb 3rd, 2003, 11:58 AM
#5
Thread Starter
Stuck in the 80s
Originally posted by crptcblade
Instead of ios::out, try ios::app
That works great. Thanks
-
Feb 3rd, 2003, 05:13 PM
#6
Monday Morning Lunatic
Originally posted by The Hobo
I would love to, however my teacher will not allow it.
crptcblade, I'll give it a try.
******* *****. I don't care what they think. Limited character arrays in a C++ program have NO PLACE WHATSOEVER. Trust me, I have been bitten on this. If your teacher has a problem, then they can come on here, and argue with those of us that have to put up with the problems caused by the ******* shoddily coded software that ends up being put out these days.
******s. They put their "qualifications" above common sense, and well known effects.
(note: rant is aimed at teachers, not you)
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 3rd, 2003, 05:18 PM
#7
Thread Starter
Stuck in the 80s
Originally posted by parksie
******* *****. I don't care what they think. Limited character arrays in a C++ program have NO PLACE WHATSOEVER. Trust me, I have been bitten on this. If your teacher has a problem, then they can come on here, and argue with those of us that have to put up with the problems caused by the ******* shoddily coded software that ends up being put out these days.
******s. They put their "qualifications" above common sense, and well known effects.
(note: rant is aimed at teachers, not you) [/B]
I agree with you, Mike. I really do. But right now all I care about is getting a grade I deserve, and stirring up controversy isn't going to get me that.
-
Feb 3rd, 2003, 05:24 PM
#8
Monday Morning Lunatic
Well. You have a choice.
1. A qualification.
2. Knowing that you are actually capable of doing something, and thinking for yourself.
Oh, FYI, I have no qualifications concerning programming whatsoever.
PS: I actually would quite like to speak to your teacher/instructor, if you can get them to PM me on here it would be greatly appreciated
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 8th, 2003, 06:33 PM
#9
And when there are buffer overflow security bugs in an app people complain
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 9th, 2003, 11:12 AM
#10
Thread Starter
Stuck in the 80s
Originally posted by CornedBee
And when there are buffer overflow security bugs in an app people complain
Go whine somewhere else. There's nothing I can do about it.
-
Feb 9th, 2003, 03:46 PM
#11
Monday Morning Lunatic
There is, it just takes guts.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 10th, 2003, 05:37 AM
#12
Exactly. Use the string class and tell your teacher to **** off. Or maybe explain to him in reasonable words that there is absolutly no reason not to use the string class and that it has many advantages in many ways.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 10th, 2003, 01:35 PM
#13
Thread Starter
Stuck in the 80s
Originally posted by CornedBee
Exactly. Use the string class and tell your teacher to **** off.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|