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
Can any constructor throw an exception? How to handle error while the constructor fails?


Assume we wish to partition the square roots of the integers from 1 to 100 in to two piles of fifty numbers every, such that the sum of the numbers in the first pile is as close as

Make QtAV Videoplayer simple integrateable for Qt Applications Project Description: I'm preparing an application for Windows and Mac using QtCreator. I want a videoplayer

Observe that our model of evaluation allows for combinations whose operators are compound expressions. (a) Use this observation to describe the behavior of the following procedu

Add a function for saving the text stored in an array to a file. Your program must check whether or not the output file already exists, and if it does, your program must ask the us

c program for padovan string   Padovan series are positive integers obtained by the following process: The Padovan series is the sequence of integers P(n) defined by the

How does an ERP System facilitates better decision making?

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: We are seeking someone to search mp3 link form audio or m3u8 for videos. Skills required are .NET, C Programming, Engineering, C# Programming