3

I have the following code:

#include <iostream>
using namepsace std;

int main() {
   cout << "Hello\nworld!" << endl;
}

On console it prints:

Hello

world!

But why world! starts from the beginning of a line wihout '\r' character?

Community
  • 1
  • 1
michalt38
  • 1,193
  • 8
  • 17
  • ASCII-1968 (USAS X3.4-1968) allowed LF alone to be used as a newline, by allowing for an “optional implicit CR”. (Apple didn't get the memo until OS X.) – Eljay Mar 26 '20 at 11:21

2 Answers2

3

While strictly speaking \n is newline and \r is carriage return, it's up to the particular console how these are interpreted. It seems your console (like most) does a carriage return on a newline.

Jasper Kent
  • 3,546
  • 15
  • 21
1

Nowadays \n usually starts at the beginning of a new line. Read more here

M_N1
  • 69
  • 11