How does the fstream work?

How does the fstream work?

Post by Magnus Mage » Wed, 11 Sep 2002 22:23:22



Hi there!

How do the fstream works?
How are the << and >> operators defined? How many bits do they read or
write?

Thanks.

Magnus

 
 
 

How does the fstream work?

Post by Nils O. Sel?sd » Wed, 11 Sep 2002 21:02:36



> Hi there!

> How do the fstream works?
> How are the << and >> operators defined? How many bits do they read or

Those are overloaded operators(in C++ you can implement your own
operators), so it depends on what you pass to them.

think of it as the class of cout have some methods, it might e.g. have
 write(char *str);
 write(int i);

Instead of several overloadad "ordinaery" methods, some operators
are rather overloaded.
So the potentional
cout.write("Test");
is almost the same as
cout << "Test";

 
 
 

How does the fstream work?

Post by Petric Fran » Wed, 11 Sep 2002 21:19:21


Hello,


> Hi there!

> How do the fstream works?
> How are the << and >> operators defined? How many bits do they read or
> write?

a nice iostream reference can be found at
  http://www.cplusplus.com/ref/iostream/

For me it halps a lot.

regards
   Petric

 
 
 

1. fstream and socket not working

I am using Sun Workshop 5.0 on Solaris 2.6.
I have created an fstream (both I & O) with a socket descriptor to an
open tcp connection. When I use the fstream for one direction, such as
reading, it works fine. When I switch to the other, such as writing, it
always fails. I am not sure what I am doing wrong. It has to be
something simple. I tried this with 2 streams, an ifstream and an
ofstream, and it worked fine. Any help would be greatly appreciated.

I think the filebuf is seeking when the ifstream/ofstream are switched.
Not sure if that is the case.

Here is some sample code, where it always fails on the write, but
always works on the read.

fstream *io = new fstream(theSocket);

io->ignore(sizeof(STARTDATATRANSFER), STARTDATATRANSFERDELIM);

if (io->fail())
{
     cerr << "got error (" << errno << ")" << endl;
else
{
     (*io) << ACKDATATRANSFER; io->flush();
     if (io->fail())
     cerr << "Write Ack to stream failed (" << errno << ")" << endl;

Sent via Deja.com http://www.deja.com/
Before you buy.

2. Linux on Dell Inspiron 9300

3. Can C++ fstream work under Linux?!

4. Help with sh script please - I'm desperate :-(

5. g++ not working, on fstream

6. SE3310 - SCSI gross phase/signal error detected SCSI bus reset hapenning randomly

7. How to make pcmcia ethernet card that works with Linux work with dos? . .

8. Adaptec AHA1542B Problems

9. HELP: Connectivity between DOS/DOS and DOS/Linux

10. relocation error using fstream

11. fstream.h

12. fork() + <fstream> = disaster!

13. fstream.h and execution problems