|
-
Jan 3rd, 2001, 12:27 PM
#1
Thread Starter
Member
Hey, how do you use a piece of code like this to APPEND a file...:?
ofstream out_stream;
out_stream.open("Mail.dat");
How do you open it for appending instead of wiping it clean each time.
Wisdom is supreme, therefore get wisdom,
though it costs all you have, get understanding.
Proverbs 4:7
-
Jan 3rd, 2001, 01:11 PM
#2
Monday Morning Lunatic
This should work:
Code:
out_stream.open("Mail.dat", ios::append);
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
-
Jan 3rd, 2001, 04:34 PM
#3
Thread Starter
Member
Ha, no working
It doesn't work....! is there a different incllude file I need to use? says 'append' is undefined....help....?
Wisdom is supreme, therefore get wisdom,
though it costs all you have, get understanding.
Proverbs 4:7
-
Jan 3rd, 2001, 04:38 PM
#4
Monday Morning Lunatic
Try including iomanip.h and ios.h
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
-
Jan 3rd, 2001, 04:46 PM
#5
Thread Starter
Member
Include
I tried including the files, iomanip.h and io.h NOT ioS.h (because ioS.h doesn't exist) and it still can't find it....
Wisdom is supreme, therefore get wisdom,
though it costs all you have, get understanding.
Proverbs 4:7
-
Jan 3rd, 2001, 04:49 PM
#6
Monday Morning Lunatic
Sorry about that...the code I had in front of me was for a different set of headers :angry:
Try ios_base::app
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
-
Jan 3rd, 2001, 04:53 PM
#7
Thread Starter
Member
Still no dice...
Ok, here's the errors::
Error: ai.cpp(62,52):Qualifier 'ios_base' is not a class or namespace name
Error: ai.cpp(62,54):Function call missing )
and here's my code::
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
#include <iomanip.h>
#include <io.h>
blah blah blah
out_stream.open("mail.dat", ios_base::app);
if (out_stream.fail())
{textcolor(RED);
cprintf("Error opening Mail output file, exiting program...");
exit(1);
can't figure out what's happening
}
Wisdom is supreme, therefore get wisdom,
though it costs all you have, get understanding.
Proverbs 4:7
-
Jan 3rd, 2001, 04:59 PM
#8
Monday Morning Lunatic
GGgggnnnckkk. I know what it is I was referring to the official headers... 
Code:
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <conio.h>
#include <ctype.h>
#include <iomanip>
using namespace std;
out_stream.open("mail.dat", ios_base::app);
if(out_stream.fail()) {
textcolor(RED);
cprintf("Error opening Mail output file, exiting program...");
exit(1);
}
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
-
Jan 3rd, 2001, 05:03 PM
#9
Thread Starter
Member
One more time...........
Ok, one more time, this is all of my code, still won't work:
/////////////////////////////////////////////////////
// AI Program By Matthew Hinman Period 2 1-02-01 //
// ---~~:Bertha:~~--- //
/////////////////////////////////////////////////////
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
#include <iomanip.h>
#include <io.h>
using namespace std;
void description();
int main()
{
char command;
char outfile[21];
char infile[21];
char mailchoice;
description();
textcolor(BLUE);
cprintf(" Welcome to 'Bertha', an AI program\r\n");
cprintf(" Just poke around, do what you like.\r\n");
cprintf(" Commands are limited to 50 characters.\r\n");
cprintf(" ----~~~::TURN CAPS-LOCK ON::~~~----\r\n");
cout << "$ ";
cin >> command;
if (command=='H')
{
cprintf("Help Options\r\n");
}
if (command=='O')
{
cprintf("Change output file\r\n");
cout << "New output file name? ";
cin >> outfile;
cout << "Outfile changed\n";
}
if (command=='I')
{
cprintf("Change input file\r\n");
cout << "New input file name? ";
cin >> infile;
cout << "Infile changed\n";
}
if (command=='M')
{
ofstream out_stream;
mail:
cprintf("Mail Options: \r\n");
cout << "S: send mail\n";
cout << " R: Read mail\n";
cout << " X: Exit\n";
cin >> mailchoice;
switch (mailchoice)
{
case 'S':
char user[11];
char mestext;
char subject[31];
out_stream.open("mail.dat", ios_base::app);
if (out_stream.fail())
{
textcolor(RED);
cprintf("Error opening Mail output file, exiting program...");
exit(1);
}
cprintf("Send Mail\r\n");
cout << "Who do you want to send mail to? ";
cin >> user;
out_stream << "NAME: " << user << endl;
cout << "Subject of the message? (0-30 characters long ONE WORD) ";
cin >> subject;
out_stream << "SUBJECT: " << subject << endl;
cout << "Message text: (~ to finish)\n";
out_stream << "MESSAGE: ";
do
{
mestext=getch();
cout << mestext;
out_stream << int(mestext);
} while (mestext!='~');
out_stream << endl << endl;
cout << "Message saved, exiting to menu\n";
goto mail;
case 'R':
cout << "Mail reading feature not yet supported";
goto mail;
case 'X':
cprintf("Exiting mail program...\r\n");
break;
default:
textcolor(RED);
cprintf("Illegal Command, re-enter\r\n");
textcolor(BLUE);
goto mail;
}
}
else cprintf("Command non-existent or not installed\r\n");
}
void description()
{
textcolor(RED);
cprintf("This Program was written by Matthew Hinman and is\r\ncopyright with no unathorized reproductions\r\n");
}
If this doesn't work, i'm going to shoot someone...
Wisdom is supreme, therefore get wisdom,
though it costs all you have, get understanding.
Proverbs 4:7
-
Jan 3rd, 2001, 05:05 PM
#10
Monday Morning Lunatic
Code:
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <conio.h>
#include <ctype.h>
#include <iomanip>
#include <io.h>
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
-
Jan 3rd, 2001, 05:07 PM
#11
Thread Starter
Member
Errrr
Error: ai.cpp(7,2):Unable to open include file 'CSTDLIB.h'
Do i need to download it?
Wisdom is supreme, therefore get wisdom,
though it costs all you have, get understanding.
Proverbs 4:7
-
Jan 3rd, 2001, 05:07 PM
#12
Monday Morning Lunatic
It doesn't have a .h extension!!!
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
-
Jan 3rd, 2001, 05:08 PM
#13
Thread Starter
Member
Errrr
It automatically added one, I'm using borland? I dunno why...
Wisdom is supreme, therefore get wisdom,
though it costs all you have, get understanding.
Proverbs 4:7
-
Jan 3rd, 2001, 05:11 PM
#14
Monday Morning Lunatic
Oh...I don't know then - I don't have borland. I'm sure it supports the standard c++ library (where the headers with no extension are from)
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
-
Jan 3rd, 2001, 05:13 PM
#15
Thread Starter
Member
Dang
Dang, that sucks, owell, thanks for your help and I guess I'll try to find the problem myself
Wisdom is supreme, therefore get wisdom,
though it costs all you have, get understanding.
Proverbs 4:7
-
Jan 3rd, 2001, 05:32 PM
#16
turbo C++ does not support the standard C++ library, but BCC 5.5 does...
and parksie, I thought you did this:
Code:
//.......
out_file.open("filename.txt", ios::app);
that works for me wheater using iostream or iostream.h
-
Jan 4th, 2001, 01:02 PM
#17
Monday Morning Lunatic
I was reading the wrong source code - that had ios::append, rather than ios_base::app.
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
-
Jan 4th, 2001, 03:26 PM
#18
I meant:
I thought you were supposed to do this:
<code was here>
-
Jan 4th, 2001, 04:27 PM
#19
Monday Morning Lunatic
That's what I interpreted from your reply .
Compiling a quick test program resulted in my second answer being the right one - as in the one you gave 
I was reading the wrong bit of source code *cries*
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
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
|