# What is the value of '\n' in Windows?

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

## Recommended Posts

Hello,

Since Windows uses two characters for a newline (13 and 10), what is the value of the C++ character '\n' in Windows? 13 or 10?

I don't have a Windows machine nearby to test it on, hence the question.

Thanks!

##### Share on other sites

Hello,

Since Windows uses two characters for a newline (13 and 10), what is the value of the C++ character '\n' in Windows? 13 or 10?

I don't have a Windows machine nearby to test it on, hence the question.

Thanks!

ascii \n = 10 , \r = 13

##### Share on other sites

0x0a, or 10 - same as elsewhere.  Newlines are handled by the C/C++ runtime so that you don't have to worry about that.

An interesting historical note is here: http://blogs.msdn.com/b/oldnewthing/archive/2004/03/18/91899.aspx

The unix ancestry of the C language carried this convention into the C language standard, which requires only "\n" (which encodes LF) to terminate lines, putting the burden on the runtime libraries to convert raw file data into logical lines.

Edited by mhagain

##### Share on other sites

Thanks!

I'm also wondering about the following:

When using getchar(), and you type some text followed by "enter", then this "enter", too, gets output by getchar.

In Unix systems, this will be a final value of 10.

In Windows, should I expect there to be both a 10 and a 13, or only a 10? In other words, if I type "a" followed by enter in the terminal, will getchar() return something three times in Windows, or only 2 times?

##### Share on other sites
Lode, you many times will receive 10 followed by 13 as if it where two separate keystrokes. Personally I normally counter act this in cros platform apps by simply ignoring the character 10 or \r. Haven't found many if any reasons to use character 10 outside of windows.

##### Share on other sites

But even while ignoring it, you have to remember that it still exists, as I recently was forced to remember

##### Share on other sites

[EDIT]
I could have sworn he said he skipped the \n, not the \r…
[/EDIT]

[EDIT2]

He did say he skipped \n (0xA or character 10).  Hence my confusion.

Dan Mayor you should correct your post to avoid confusion. \r = 0x0D (13) and \a = 0x0A (10).

[/EDIT2]

L. Spiro

Edited by L. Spiro

##### Share on other sites

You can always do this:

char c='\n';

char out[8];
sprintf(out,"%d",c);
// output it somehow
// or just do a breakpoint and look at c


1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
13
5. 5
frob
12

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633665
• Total Posts
3013246
×