'\n' ascii code

Hello everyone! Even though this seems to be a simple question, it seems to have a lot of answers. I want to know what the ascii code of escape '\n' character (new line, generated by pressing enter key) is. I thought that is 255, as i output-ed char(255) and it generated a new line. But after that I typed "cout<<int('\n') and I was given 10 value. But when I checked it on other sites, there were other answers , involving 13 and 26 values. That being said, what do you think? Does it deserve or no to have a fixed ascii code?
The escape sequences '\n'is not required to be equivalent to a specific control character in a particular character encoding.

1. The escape sequence '\n' maps to some unique implementation-defined value that can be stored in a single char.

2. When writing to a stream in text mode, '\n' is transparently translated to the native newline sequence on the that particular system (which may be longer than one character).
When reading from a stream in text mode, this native newline sequence is translated back to '\n'.
(In binary i/o mode, no such translation is performed.)
I didn't comprehend anything, I'm sorry :(
The value of the new line character may vary from place to place.

To find out what it is on the implementation that is being used, run this program:
1
2
3
4
5
6
#include <iostream>

int main()
{
    std::cout << "value of the new line character is " << int( '\n' ) << '\n' ;
}

http://coliru.stacked-crooked.com/a/a25a5e590df67c67

end of line differs across operating systems and all.
it is usually one of

10
13
10 13 (2 chars)

26 is less common.

it has nothing to do with deserving. It simple IS that various operating systems and platforms were developed 40 years ago with various approaches to this, and for historical reasons, they never converged on one single method.

Last edited on
Now I see, it was just that I thought all the languages and OSs use the same assignments.
all languages will conform to the OS that you are working on.
That is about all you can hope for.
Most modern text editors figure it out on the fly, so that is nice also if you move a file from one to another.

you have to recompile c for every OS anyway, unless running in a vm or something, so its not a huge deal.


Topic archived. No new replies allowed.