Developer community
0 votes
asked by | 34 views

1 Answer

0 votes
Best answer

Use std::ios::binary.

Some operating systems differentiate between text and binary modes. In text mode, end-of-line
sequences and possibly other things are translated; in binary mode, they are not. For example, in text mode under Windows, "\r\n" is translated into "\n" on input, and the reverse on output.
To read a file in binary mode, use something like this:
void readBinaryFile(const std::string& filename)
std::ifstream input(filename.c_str(), std::ios::in | std::ios::binary);
char c;
while (input.get(c)) { something with c here...
Note: input >> c discards leading whitespace, so you won't normally use that when reading
binary files.


answered by

Related questions

0 votes
1 answer
asked by Smita Advisor (7.1k points) 10 23 42 | 121 views
0 votes
1 answer
asked by allison Sr Member (1.5k points) 11 26 40 | 48 views
0 votes
1 answer
asked by daniel Advisor (5.6k points) 1 7 14 | 63 views
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true


C Books Guide and List
C++ Books Guide and List
Best Java Books

3.8k questions

4k answers


10.7k users

3,751 questions
4,046 answers
10,709 users