2 Replies - 1172 Views - Last Post: 17 February 2010 - 04:44 AM Rate Topic: -----

#1 pingking123   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 19-November 09

Verifying that fstream is in binary mode

Posted 17 February 2010 - 03:09 AM

Hi,
I have a function that recieves a pointer to an fstream object which is already open. It is very importatn that the function will verify that the fstream object is in binary mode. But the function must recieve the fstream pointer when it's already open and not open it in the function:

void WritingThingToBinaryFS (std::fstream * BinaryFS)
{
// How do I verify that BinaryFS was opened in binary mode?
}


Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Verifying that fstream is in binary mode

#2 pdkharkar   User is offline

  • D.I.C Regular
  • member icon

Reputation: 65
  • View blog
  • Posts: 345
  • Joined: 19-January 09

Re: Verifying that fstream is in binary mode

Posted 17 February 2010 - 03:19 AM

 fstream binary_file("c:\\test.dat",ios::out|ios::binary|ios::app); 

well this is the example you could get something
ios:: binary mode enables us to open the file in the binary mode
and
ios::app mode enables us to open the file in append mode
Was This Post Helpful? 0
  • +
  • -

#3 sarmanu   User is offline

  • D.I.C Lover
  • member icon

Reputation: 967
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: Verifying that fstream is in binary mode

Posted 17 February 2010 - 04:44 AM

When you create the fstream object, simply specify the "ios::binary" flag, like pdkharkar suggested. Here's an example:
std::fstream object("myfile.txt", ios::out | ios::binary); // specifies the binary flag
// call function:
WritingThingToBinaryFS(&object);


You can't check if BinaryFS was opened in binary mode or not (in the function).
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1