what do i write to a text file to make notepad see a carriage return?

zsouthboy

Platinum Member
Aug 14, 2001
2,264
0
0
After I write a string to a file, i'd like to go to the next line for the next..

Isn't there a code (^M$ or something<- i tried that, btw, didn't work) that is carriage return?

EDIT: Whoa, that post was barely legible... i need some coffee for sure...

 

joshg

Golden Member
Jul 3, 2001
1,359
0
0
It depends on what language you are working in.

For C, as singh posted, it's \r\n, \r = carriage return, and \n = new line

For other languages, it's a little different. In VB you can use the constant vbCrlf, which is actually just Chr(10) & Chr(13) (if I remember right.. it might be 13 & 10... heh)

Plus there are other options for other languages...
 

zsouthboy

Platinum Member
Aug 14, 2001
2,264
0
0
heh.. of course its not \r\m, that would be too easy..

Lemme try explain better.

VC++.

I am taking a string, and writing it to a file (log.txt).
I want to put a carriage return after every time I write the string.
\r\n (which are C++ anyway) and ^M$ do not work..

suggestions?
 

zsouthboy

Platinum Member
Aug 14, 2001
2,264
0
0
I want the carriage return to appear in NotePad when I open it using NotePad... that's what i mean, what symbols does notepad actually use so i can write them to the file along with the strings?
 

zsouthboy

Platinum Member
Aug 14, 2001
2,264
0
0
okay... NOW \r\n works... but it puts a wierd character in..

&yacute;

/\
|
puts that on the next line.. hmm
 

zsouthboy

Platinum Member
Aug 14, 2001
2,264
0
0
Okay forget it... i'm going to create a blank .txt file, hit enter once, and find out what the hell is in it.... argh...
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
ofstream out("foobar.txt");
out << "hello world" << endl;
out << "hello again" << endl;


Or am I missing something?
 

zsouthboy

Platinum Member
Aug 14, 2001
2,264
0
0
yes, that would be the easy way to do it.

but, i do things the hard way... lol..

i'm using the CFile class to do file io...



I figured out what the two characters are, and yes, they are 13 and 10 (0D and 0A accordingly)... now, figure out how to write hex to a file...
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
You don't need to write hex, hex and decimal are just different ways of representing the same value.

Using "\r\n" is no different from using (char)13 (char)10, afaik. If you are using C++ you might as well use its facilities to the fullest extent and just use endl. If you want to code c then just code c.