In binary mode how can i open a stream?, C/C++ Programming

A: Use std::ios::binary.

Some operating systems differentiate among text and binary modes. In text mode, end-of-line sequences and perhaps other things are translated; in binary mode, they are not. For instance, in text mode under Windows, "\r\n" is translated in "\n" on input, & the reverse on output.

To read a file in binary mode, employ something like this:

#include

#include

#include

void readBinaryFile(const std::string& filename)

{

std::ifstream input(filename.c_str(), std::ios::in | std::ios::binary);

char c;

while (input.get(c)) {

...do something with c here...

}

}

Note : input >> c discards leading whitespace, thus you won't normally employ that when reading binary files.

 

Posted Date: 3/21/2013 7:44:14 AM | Location : United States







Related Discussions:- In binary mode how can i open a stream?, Assignment Help, Ask Question on In binary mode how can i open a stream?, Get Answer, Expert's Help, In binary mode how can i open a stream? Discussions

Write discussion on In binary mode how can i open a stream?
Your posts are moderated
Related Questions
Constructors By definition, a constructor function of some class is a member function that automatically gets implemented whenever an instance of the class to which the constru

Can you think of a condition where your program would crash without attaining the breakpoint that you set at the starting of main()? A: C++ let for dynamic initialization of glo

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

Project Description: collect / modify person records / photo images/ lookup / facebook iphone and ipad App basic function : 1 user will configure facebook connection

Project Description: I am seeking someone who can make this modem work with Linux Caller ID on Ubuntu present stable version. Skills required are C Programming, Python

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

Selection sort - C program: Write a program to define a selection sort. void main()  {   clrscr();   int a[100],ch,n;   cout   cin>>n;   for (int i=0;i


Sorted directory - C++ program: Write a program in c to sorting a directory. int main( int argc, char *argv[] ) {     if( argc 3 )         {         cerr

What are pre-processor directives? - Pre-processor directives are placed at the beginning of a C program. They begin with # symbol. - This is the place, where library files