Hi,

Here's an example for reading a file:

#include <fstream>
#include <iostream>

using namespace std;

string str;
ifstream inf("test.txt", ios::in);

while(!inf.eof()) {
        inf >> str;
        cout << str << endl;
}


For writing it's almost the same:

ofstream outf("test.txt", ios::out);
outf << "Hello World";


HTH

Cheers,
Matt.



** On Wed Mar 10, 2004 at 10:40:44PM +1100, Lucas King ([EMAIL PROTECTED]) wrote:
> hello,
> 
> a somewhat technical question - i am trying to associate a file 
> descriptor with a file pointer using the C++ fstream class.  this 
> function is an extension to the C++ library.
> 
> in the documentation that i downloaded from the WEB 
> (http://nf.apac.edu.au/facilities/sc/compaq_mirror3/progtool/cplus/basic_fstream_3c__std.htm)
>  
> it shows a constructor, explicit basic_fstream(fd).  i take this to mean 
> that it can be done.  however, it does not provide an example on how to 
> invoke the method.
> 
> basically, what i am trying to do is fdopen(), a Linux system call, but 
> using C++.
> 
> please do not assume that my knowledge of C++ is extensive.  this is by 
> no means the case.
> 
> any feedback on how to do this or a pointer to further reference 
> material will be appreciated.
> 
> many thanks,
> 
> Lucas
> 
> 
> 
> 
> ************************************************************************
> The information contained in this e-mail message and any accompanying files
> is or may be confidential.If you are not the intended recipient, any use, 
> dissemination, reliance,forwarding, printing or copying of this e-mail or
> any attached files is unauthorised.This e-mail is subject to copyright. No
> part of it should be reproduced,adapted or communicated without the written
> consent of the copyright owner.If you have received this e-mail in error,
> please advise the sender immediately by return e-mail, or telephone and
> delete all copies.Fairfax does not guarantee the accuracy or completeness
> of any information contained in this e-mail or attached files. Internet
> communications are not secure, therefore Fairfax does not accept legal
> responsibility for the contents of this message or attached files.
> ************************************************************************
> 
> -- 
> SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
> Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Attachment: pgp00000.pgp
Description: PGP signature

-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to