Jump to content
  • Advertisement
Sign in to follow this  
Vexorian

differences between \r\n and \n

This topic is 4861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I eventually had to learn this, I knew it! , now that I am making a font thing for my game I finally figure out that I have to learn the difference between \r\n and \n

Share this post


Link to post
Share on other sites
Advertisement
\r\n is a carriage return followed by a newline. \n is just the newline. Since the days of teletype machines is mostly gone, \r\n is usually converted to just \n and handled that way.

Share this post


Link to post
Share on other sites
Some operating systems use the value 0x0a ('\n') to mark the end of a line. Some use the value 0x0d ('\r') to mark the end of a line. Some use the sequence 0x0d,0x0a ("\r\n").

The C and C++ libraries automatically convert to the proper marker when a '\n' is written to file or stream in text mode, and convert from the end-of-line marker to '\n' when reading from a file or stream in text mode.

Share this post


Link to post
Share on other sites
For maximal compatibility you might want to use "\r\n" whenever possible. Some programs such as notepad don't interpret "\n" as "\r\n" hence don't display the text correctly.

Share this post


Link to post
Share on other sites
Quote:
Original post by Skeleton_V@T
For maximal compatibility you might want to use "\r\n" whenever possible. Some programs such as notepad don't interpret "\n" as "\r\n" hence don't display the text correctly.


That's not really true; as long as you use the correct text mode flags on file output, the OS should convert \n to the correct line terminator for the operating system.

Share this post


Link to post
Share on other sites
Quote:
Original post by Skeleton_V@T
For maximal compatibility you might want to use "\r\n" whenever possible. Some programs such as notepad don't interpret "\n" as "\r\n" hence don't display the text correctly.


On the other hand, some programs don't expect the '\r' before \n, and so, they end up printing something like ^M at the end of every line.

Share this post


Link to post
Share on other sites
I know when I did some .NET programming last week and used the text edit box I had to use \r\n to get a new line. Just using \n resulted in garbage.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by njpaul
I know when I did some .NET programming last week and used the text edit box I had to use \r\n to get a new line. Just using \n resulted in garbage.


.Net has Environment.NewLine to solve such problems

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Quote:
Original post by njpaul
I know when I did some .NET programming last week and used the text edit box I had to use \r\n to get a new line. Just using \n resulted in garbage.

.Net has Environment.NewLine to solve such problems

OT: But it really _should_ be transparent in WinForms controls, too sad it isn't. Getting/setting text for a control should do the same thing as opening a file in text-mode: writing \n should be converted to \r\n and reading \r\n should be converted to \n.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!