Why does io:format support ~n when \n does the same thing?

别说谁变了你拦得住时间么 提交于 2019-12-06 01:04:12

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/13215033/why-does-ioformat-support-n-when-n-does-the-same-thing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!