문제

These two give identical output:

1> io:format("Hello, world!~n").
Hello, world!
ok
2> io:format("Hello, world!\n").
Hello, world!
ok

Why does io:format support ~n when \n does the same thing? Are there any differences?

도움이 되었습니까?

해결책

According to "Programming Erlang", ~n outputs the platform-specific new line sequence (\n on Unix, \r\n on Windows, etc.). I think \n just writes the \n character, but am not sure.

다른 팁

According to io document, The general format of a control sequence is ~F.P.PadModC. So the format must begin with ~, and character n is one of the control sequences with the definition Writes a new line. \n is not a format.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top