Characters output to a file, and other online

Category: C/C++ -> C Author: zff64 Date: 2001-10-20 20:34:18
2001-10-20 20:34:18
I have to file output a ASCLL code 10 (LF) character, they found the last file is inserted before each LF a CR (carriage return) character, that a LF characters in the file into a CR , LF two consecutive characters I want to know how to avoid this situation. online, thank you!!!
2001-10-20 20:45:12
the way you write binary files, you can, give it a try , I wrote the following program:
# include <fstream>
# include <iostream>
using namespace std;
void main ()
FILE * fp;
char c;

c = 0x0A;
fp = fopen ("output" ;, "wb +");
if (fp == NULL) {
printf ("write file error \ n");
exit (1);
putc (c, fp);
fclose (fp);

fp = fopen (" ; output "," r ");

while (1) {
c = getc (fp);
if (c == -1)
printf ("c is% d \ n", c);

fclose (fp);

2001-10-20 20:53:29
Upstairs was right, but there's an easier
ofstream ofile ( "c: \ \ output.bmp", ios_base :: binary);
2001-10-20 21:08:17
binary open,

Do not use Notepad
I guess it is your notepad The problem, it encounters a \ 0xa put it into a carriage return and line feed
In fact, the general cr and lf is paired
2001-10-20 21:46:57
should be the wrong way to open the file you Ah, I used ultraedit tried it, re-open the front, it will ask you to open a dos mode, if available, will be adding a carriage return, is not the case, or a newline ah. give it a try!
2001-10-20 22:26:10
I am using UltraEdit-32 open, but also in hex edit mode.
I clearly see the new file more than the original document a few bytes (there are several LF characters on a few more bytes).
explain that I was in a period of the original document bytes read into the buffer, and then write the contents of the buffer in the new file.
I actually use the following statement is the same result. also requested guidance!!!
ofstream ofile ("output.bmp");
char a = 10 ;
ofile << a;
2001-10-20 22:56:37
I have tried, the situation is just like yours, I think this is probably the window system is the problem, if possible under unix you try, I think I should not like
2001-10-20 23:30:22
This can not, I have this program is to run under Windows And I did not UNIX systems.
2001-10-21 00:05:12
master Come help ah!!!!
2001-10-21 00:44:36
Thank zxm954712 (zhangxiaoming), topikachu (Phi) two!!!
If you use the former method, I The program will be slightly altered, I still use the latter method.