Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6559191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:17:36+00:00 2026-05-25T13:17:36+00:00

Recently I was working with some strings, text input, things like that and I

  • 0

Recently I was working with some strings, text input, things like that and I realized I got little confused about 2 characters – LF(10) and CR(13). Every time I needed to start new line I used std::endl for c++ string and \n which is LF for c-strings. However I’m now using one library which on return key press sends me not LF but CR key code. I read on wikipedia that usage is as follows:

CR+LF: Microsoft Windows, DEC TOPS-10, RT-11 and most other early non-Unix and non-IBM OSes, CP/M, MP/M, DOS (MS-DOS, PC-DOS, etc.), Atari TOS, OS/2, Symbian OS, Palm OS
LF+CR: Acorn BBC spooled text output.
CR:    Commodore 8-bit machines, Acorn BBC, TRS-80, Apple II family, Mac OS up to version 9 and OS-9
LF:    Multics, Unix and Unix-like systems (GNU/Linux, AIX, Xenix, Mac OS X, FreeBSD, etc.), BeOS, Amiga, RISC OS, and others.
RS:    QNX pre-POSIX implementation.

But I never really noticed need for CR on windows, everything gets printed anyway at right location. CR, again according to wikipedia, was used in times of type writers for returning that writing head to begining of line, and then LF for scrolling one line bellow.

My question is if it’s really necessary these days to use CR and why. What systems could possibly fail to output text correctly if only LF is used? Does printers still require CR and if so, does OS automaticly interpret LF as both new line and return to start of line or CR must be still hardcoded in data that I sent for printing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:17:37+00:00Added an answer on May 25, 2026 at 1:17 pm

    Inside your C and C++ programs all you need (at least, when dealing just with the standard library) is \n, which, when sent to any C/C++ stream opened in text mode (i.e. when you don’t specify b into the fopen and ios::bin for C++ streams), is automatically translated to the line terminator of the current platform. That’s why on Windows you can just write \n to any stream and it becomes “magically” CRLF into the file/on the console.

    The whole binary/text mode thing exist for this purpose: when you are writing a text file it’s useful to have this translation (this way inside your strings you can just have \n as line terminator without worrying about the specific platform line terminator), but when you’re writing a binary file \n is just a byte like the others and should not be translated, otherwise you get corrupted data.

    *NIX systems that use just LF (which is \n) don’t actually do any translation, but it’s still good to specify correctly binary/text mode for portability/clarity purposes.

    Using always endl in C++ is a common mistake, \n is enough to get the translation to the platform-specific line terminator.

    What endl does more than \n is to flush the stream buffer, which can be useful in some limited circumstances (e.g. outputting something on a console before a long operation), but in general just slows down the IO (on consoles it’s usually not noticeable, but on files it is). I usually just use \n and add a std::flush when a flush is actually needed.


    This for what concerns the standard library; when dealing with other libraries YMMV and you should check their documentation to see if they follow the standard C convention or they require strings to contain the platform-specific line terminator.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was working on some code recently and came across a method that had
I recently encountered a situation in some code I am working on that doesn't
I'm working on a site that is using Facebook Connect and recently made some
For some odd reason I recently got an error when working on an Android
Recently I'm working on some air stuff, and I am using Flash Builder and
Recently I've been working on some embedded devices, where we have some structs and
I've been working with some ExternalDataExchange - based communication in WF recently. My understanding
I've been working with some event handling in Javascript and recently decided to migrate
I've recently begun working on a project regarding GUI building using some form of
I was recently working on an application that sent and received messages over Ethernet

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.