Click here to Skip to main content
16,008,954 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Ignoring \n in a binary file during reading Pin
Mustafa Ismail Mustafa11-Dec-08 2:46
Mustafa Ismail Mustafa11-Dec-08 2:46 
GeneralRe: Ignoring \n in a binary file during reading Pin
Stuart Dootson11-Dec-08 2:58
professionalStuart Dootson11-Dec-08 2:58 
GeneralRe: Ignoring \n in a binary file during reading Pin
Mustafa Ismail Mustafa11-Dec-08 3:04
Mustafa Ismail Mustafa11-Dec-08 3:04 
GeneralRe: Ignoring \n in a binary file during reading Pin
Stuart Dootson11-Dec-08 4:32
professionalStuart Dootson11-Dec-08 4:32 
GeneralRe: Ignoring \n in a binary file during reading Pin
Mustafa Ismail Mustafa11-Dec-08 4:41
Mustafa Ismail Mustafa11-Dec-08 4:41 
GeneralRe: Ignoring \n in a binary file during reading Pin
Stuart Dootson11-Dec-08 6:50
professionalStuart Dootson11-Dec-08 6:50 
GeneralRe: Ignoring \n in a binary file during reading Pin
Mustafa Ismail Mustafa11-Dec-08 10:34
Mustafa Ismail Mustafa11-Dec-08 10:34 
GeneralRe: Ignoring \n in a binary file during reading [modified] Pin
Stuart Dootson11-Dec-08 12:53
professionalStuart Dootson11-Dec-08 12:53 
I've just tried your code on OS X - worked fine there as well.

One last suggestion - you could try using the C file handling functions (open, read, close), like so:

int fd = open(fname, O_RDONLY);
const int nBytesRead = read(fd, buffer, 1000);
close(fd);


That at least tells you how many bytes it's read?

[edit]In Visual C++, this probably ought to be:

int fd = _open(fname, _O_RDONLY|_O_BINARY);
const int nBytesRead = _read(fd, buffer, 1000);
_close(fd);


VC++ uses the "ISO C++ conformant" names rather than the POSIX API names...ho-hum.

[/edit]


On the same note - std::ifstream has a method called gcount that tells you how much the last read actually read:

binFile.read(buffer, 1000);
std::cout << binFile.gcount() << std::endl;


Just tried both of those on OS X - both give the expected results with files that contain embedded NULLs.

modified on Thursday, December 11, 2008 7:00 PM

GeneralRe: Ignoring \n in a binary file during reading Pin
Mustafa Ismail Mustafa11-Dec-08 21:03
Mustafa Ismail Mustafa11-Dec-08 21:03 
GeneralRe: Ignoring \n in a binary file during reading Pin
Stuart Dootson11-Dec-08 21:11
professionalStuart Dootson11-Dec-08 21:11 
GeneralRe: Ignoring \n in a binary file during reading Pin
Mustafa Ismail Mustafa11-Dec-08 21:44
Mustafa Ismail Mustafa11-Dec-08 21:44 
GeneralRe: Ignoring \n in a binary file during reading Pin
Stuart Dootson11-Dec-08 23:11
professionalStuart Dootson11-Dec-08 23:11 
GeneralRe: Ignoring \n in a binary file during reading Pin
Mustafa Ismail Mustafa12-Dec-08 1:00
Mustafa Ismail Mustafa12-Dec-08 1:00 
GeneralRe: Ignoring \n in a binary file during reading Pin
Luc Pattyn11-Dec-08 3:07
sitebuilderLuc Pattyn11-Dec-08 3:07 
GeneralRe: Ignoring \n in a binary file during reading Pin
Mustafa Ismail Mustafa11-Dec-08 3:18
Mustafa Ismail Mustafa11-Dec-08 3:18 
GeneralRe: Ignoring \n in a binary file during reading Pin
Luc Pattyn11-Dec-08 3:40
sitebuilderLuc Pattyn11-Dec-08 3:40 
GeneralRe: Ignoring \n in a binary file during reading Pin
Mustafa Ismail Mustafa11-Dec-08 3:48
Mustafa Ismail Mustafa11-Dec-08 3:48 
GeneralRe: Ignoring \n in a binary file during reading Pin
Luc Pattyn11-Dec-08 4:32
sitebuilderLuc Pattyn11-Dec-08 4:32 
GeneralRe: Ignoring \n in a binary file during reading Pin
Mustafa Ismail Mustafa11-Dec-08 4:45
Mustafa Ismail Mustafa11-Dec-08 4:45 
AnswerRe: Ignoring \n in a binary file during reading Pin
VentsyV11-Dec-08 6:55
VentsyV11-Dec-08 6:55 
GeneralRe: Ignoring \n in a binary file during reading Pin
Mustafa Ismail Mustafa11-Dec-08 10:36
Mustafa Ismail Mustafa11-Dec-08 10:36 
QuestionRe: Ignoring \n in a binary file during reading Pin
David Crow11-Dec-08 8:13
David Crow11-Dec-08 8:13 
AnswerRe: Ignoring \n in a binary file during reading Pin
Mustafa Ismail Mustafa11-Dec-08 10:39
Mustafa Ismail Mustafa11-Dec-08 10:39 
GeneralRe: Ignoring \n in a binary file during reading Pin
bulg11-Dec-08 12:13
bulg11-Dec-08 12:13 
Questionalgorithms of combination Pin
mayamay11-Dec-08 2:31
mayamay11-Dec-08 2:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.