|
-
Jul 15th, 2002, 05:14 AM
#1
Thread Starter
Addicted Member
Writing to a file (Im a newbie :P)
Well Im new to C++ and I am using "bloodShed Dev C++" as my compiler. I would like to write to a text file "C:\anser.txt" but the I cant get the code I was given to work 
Could someone please tell me how to write to a text file? )
When you ask a question, try and answer a few 
-
Jul 15th, 2002, 09:28 AM
#2
Frenzied Member
#include <fstream.h>
#include <stdlib.h>
#include <iostream.h>
int main()
{
ofstream outfilie("answer.txt", ios::trunc);
if(outfile.fail())
{
cout<<"File Error"<<endl;
exit(1);
}
outfile<<"Test"<<endl;
return 0;
}
-
Jul 15th, 2002, 03:56 PM
#3
Thread Starter
Addicted Member
woohoo
It works! Thanks so berry much
When you ask a question, try and answer a few 
-
Jul 16th, 2002, 12:00 PM
#4
Monday Morning Lunatic
Originally posted by SteveCRM
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ofstream outfile("answer.txt", ios::trunc);
if(!outfile) {
cerr << "File Error" << endl;
return -1; // or 1 or something non-zero
}
outfile << "Test" << endl;
}
Ummmm...see the corrections
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
|