Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating a LF only with Microsoft c++

Status
Not open for further replies.

ktrumbla

MIS
Oct 24, 2001
13
US
I am trying to create an output file to be used on an AIX system which does not want to see a CRLF at the end of line. How do I tell my program to only give me the LF? I have tried '\n', "\n", and #define "\x0a" none of these work. Is there a way or does microsoft know best and always forces the CR?
I am using MS c++ V6.0 to compile my program.
I can strip the CR on the Unix side but I am trying to avoid that.
 
What function are you using to write to the file?

Chip H.
 
here is the line of code used for the output.
field[] is a string array
outputfile << field[1] << &quot;\n&quot;;
 
try to create a binary file and write the 0x0a directly.
#include <stdio.h>
#include <string.h>

FILE *stream;

void main( void )
{

stream = fopen( &quot;test2.txt&quot;, &quot;wb&quot; );
char s1[80] = &quot;testttyyy\x0a&quot;;
fwrite(s1,1,10,stream);
fclose( stream );
}
 
Could you do something as simple as defining a character as being just the line feed and outputting that?

char lf = 10;
outputfile << field[1] << lf; ----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Thank you all for the help I have not tried writing to the file in binary but that sounds like the correct path.
the
char lf = 10;
outputfile << field[1] << lf;
did not work.
I was reading from the MSDN and found that ofstream forces the CRLF
 
try &quot;\r\n&quot; instead of just &quot;\n&quot;

gives two CRs
 
low level writing a LF to a text file forces the CRLF. writing to the binary file will put whatever you like in it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top